Tizen 2.0 Release
[samples/web/TizenWinset.git] / main.js
1 $(document).delegate("#main", "pageinit", function() {
2         $("#main .ui-btn-back").bind("vclick", function() {
3                 tizen.application.getCurrentApplication().exit();
4                 return false;
5         });
6 });
7
8 $( document ).bind("pagecreate", function () {
9         /* Color widget demo */
10         $("input[type='checkbox'][data-widget-type-list]").bind("change", function() {
11                 var ls = $( this ).attr("data-widget-type-list").split(","),
12                         page = $( this ).closest(":jqmData(role='page')"),
13                         disabled = $( this ).is(":checked");
14
15                 $.each(ls, function( idx, widgetType ) {
16                         var ar = widgetType.split("-");
17
18                         if ( ar.length === 2 ) {
19                                 page.find(":" + widgetType)[ar[1]]( "option", "disabled", disabled );
20                         }
21                 });
22         });
23
24         $('#scroller-demo').bind('pageshow', function ( e ) {
25                 $page = $( e.target );
26                 /*
27                  * many options cannot be set without subclassing since they're
28                  * used in the _create method - it seems as if these are for
29                  * internal use only and scrollDuration is only changable by
30                  * chance.
31                  */
32                 var $scroller2List = $('#scroller2').find('ul');
33                 $scroller2List.scrollview( 'option','scrollDuration','10000' );
34
35                 // only works by manipulating css
36                 // the only other way is to use attribute 'scroll-method="scroll"' in html
37                 $('#scroller2 .ui-scrollbar').css( 'visibility','hidden' );
38
39                 /*
40                  * make toggle button switch scroll bars on and off
41                  */
42                 var scrollBarVisible = $('#scroller2').find('.ui-scrollbar').css('visibility') === "visible";
43
44                 var $toggleScrollBars = $('#toggleScrollBars');
45                 $toggleScrollBars.attr( "checked", scrollBarVisible ).checkboxradio("refresh");
46
47                 /* the 'label' is the thing that is clicked, not the input element */
48                 var $label = $toggleScrollBars.siblings('label').attr( 'for', '#toggleScrollBars' );
49                 $label.bind("click", function () {
50                         var $scrollBar = $('#scroller2').find('.ui-scrollbar');
51                         var scrollBarVisible = $scrollBar.css('visibility') === "visible";
52                         var newVisibility = scrollBarVisible ? "hidden" : "visible";
53                         $scrollBar.css( 'visibility', scrollBarVisible ? "hidden" : "visible" );
54                 });
55         });
56
57         $("#demo-date").bind("date-changed", function ( e, newDate ) {
58                 $("#selected-date1").text( newDate.toString() );
59         });
60
61         $("#demo-date2").bind("date-changed", function ( e, newDate ) {
62                 $("#selected-date2").text( newDate.toString() );
63         });
64
65         $("#demo-date3").bind("date-changed", function ( e, newDate ) {
66                 $("#selected-date3").text( newDate.toString() );
67         });
68
69         $("#demo-date4").bind("date-changed", function ( e, newDate ) {
70                 $("#selected-date4").text( newDate.toString() );
71         });
72
73         $('#noti-demo').bind('vmouseup', function ( e ) {
74                 $('#notification').notification('open');
75         });
76
77         $('#noti-icon1').bind('vclick', function ( e ) {
78                 $('#notification').notification('icon', './test/icon02.png');
79         });
80
81         $('#noti-icon2').bind('vclick', function ( e ) {
82                 $('#notification').notification('icon', './test/icon01.png');
83         });
84
85         $('#gallery-demo').bind('pageshow', function () {
86                 $('#gallery').gallery('add', './test/01.jpg');
87                 $('#gallery').gallery('add', './test/02.jpg');
88                 $('#gallery').gallery('add', './test/03.jpg');
89                 $('#gallery').gallery('add', './test/04.jpg');
90                 $('#gallery').gallery('add', './test/05.jpg');
91                 $('#gallery').gallery('add', './test/06.jpg');
92                 $('#gallery').gallery('add', './test/07.jpg');
93                 $('#gallery').gallery('add', './test/08.jpg');
94                 $('#gallery').gallery('add', './test/09.jpg');
95                 $('#gallery').gallery('refresh', 3);
96         });
97
98         $('#gallery-demo').bind('pagebeforehide', function () {
99                 $('#gallery').gallery('empty');
100         });
101
102         $('#gallery-add').bind('vmouseup', function ( e ) {
103                 $('#gallery').gallery('add', './test/10.jpg');
104                 $('#gallery').gallery('add', './test/11.jpg');
105                 $('#gallery').gallery('refresh');
106         });
107
108         $('#gallery-del').bind('vmouseup', function ( e ) {
109                 $('#gallery').gallery('remove');
110         });
111
112         $('#selectioninfo-demo').bind('vmouseup', function ( e ) {
113                 $('#smallpopup_selectioninfo').notification( "text",
114                         $("#dayselector1").find(".ui-checkbox-on").length + " items are selected" );
115                 $('#smallpopup_selectioninfo').notification('open');
116         });
117
118         $('#groupindex-demo').bind('pageshow', function () {
119                 $('#groupindex').scrolllistview();
120         });
121
122         $("#showVolumeButton").bind("vclick", function ( e ) {
123                 $("#myVolumeControl").volumecontrol("open");
124         });
125
126         $("#volumecontrol_setBasicTone").bind("change", function ( e ) {
127                 var basicTone = !($("#volumecontrol_setBasicTone").next('label')
128                                 .find(".ui-icon").hasClass("ui-icon-checkbox-on"));
129
130                 if ( basicTone ) {
131                         $("#myVolumeControl").volumecontrol( "option", "basicTone", true );
132                         $("#myVolumeControl").volumecontrol( "option", "title", "Basic Tone" );
133                 } else {
134                         $("#myVolumeControl").volumecontrol( "option", "basicTone", false );
135                         $("#myVolumeControl").volumecontrol( "option", "title", "Volume" );
136                 }
137         });
138
139         $("#myoptionheader").bind('collapse', function () {
140                 console.log('option header was collapsed');
141         });
142
143         $("#myoptionheader").bind('expand', function () {
144                 console.log('option header was expanded');
145         });
146
147         /* Gen list : Dummy DB load */
148         $(".virtuallist_demo_page").live("pagecreate", function () {
149                 /* ?_=ts code for no cache mechanism */
150                 $.getScript( "./virtuallist-db-demo.js", function ( data, textStatus ) {
151                         $("ul").filter( function () {
152                                 return $( this ).data("role") == "virtuallistview";
153                         }).addClass("vlLoadSuccess");
154
155                         $(".virtuallist_demo_page").die();
156                         $("ul.ui-virtual-list-container").virtuallistview("create");
157                 });
158         });
159
160         /*Expandable list : Dummy DB load*/
161         $("#genlist_extendable_page").live("pagecreate", function ( el ) {
162                 /*?_=ts code for no cache mechanism*/
163                 $.getScript( "./virtuallist-db-demo.js", function ( data, textStatus ) {
164                         $("ul").filter( function () {
165                                 return $( this ).data("role") == "extendablelist";
166                         }).addClass("elLoadSuccess");
167
168                         $("#genlist-extendable-page").die();
169                         $("ul.ui-extendable-list-container").extendablelist("create");
170                         // TODO: 'create' is called twice!!
171                 });
172         });
173
174         // Expand all textarea height automatically
175         $('#ButtonNolist').live( "pagecreate", function ( ev ) {
176                 var page = $( ev.target );
177                 $( page ).bind( 'pageshow' , function ( ) {
178                         var textarea = page.find('textarea');
179                         $( textarea ).each( function ( idx, el ) {
180                                 var h = Math.max( el.clientHeight, el.scrollHeight );
181                                 $( el ).height( h );
182                         } );
183                 } );
184         } );
185
186
187 });
188
189 $(document).bind( "pageinit" , function() {
190         $.mobile.tizen.enableSelection( $("div:jqmData(role='page')"), 'none');
191 });
192 $(document).ready( function () {
193         // add current datetime with browser language format
194         // NOTE: Globalize.* functions must be run after docoument ready.
195         $('#current_date').html(Globalize.culture().name + " -- " +
196                                 Globalize.format( new Date(), "F" ));
197         $('#html_font_size').html('html font size:' + $('html').css('font-size'));
198 });