[TemporaryStorage] add files required for SDK build
[samples/web/TemporaryStorage.git] / tizen-web-ui-fw / latest / js / src / widgets / jquery.mobile.tizen.tabbar.js
1
2 /* ***************************************************************************
3  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  * ***************************************************************************
23  *
24  * jQuery Mobile Framework : "tabbar" plugin
25  * Copyright (c) jQuery Project
26  * Dual licensed under the MIT or GPL Version 2 licenses.
27  * http://jquery.org/license
28  * Authors: Jinhyuk Jun <jinhyuk.jun@samsung.com>
29 */
30
31 /**
32  *  Tabbar can be created using data-role = "tabbar" inside footer 
33  *  Framework determine which tabbar will display with tabbar attribute
34  *
35  * Examples:
36  *         
37  *     HTML markup for creating tabbar: ( 2 ~ 5 li item available )
38  *     icon can be changed data-icon attribute (customized icon need)
39  *         <div data-role="footer" data-position ="fixed">
40  *              <div data-role="tabbar">
41  *                     <ul>
42  *                            <li><a href="#" class="ui-btn-active">Menu</a></li>
43  *                            <li><a href="#">Save</a></li>
44  *                            <li><a href="#">Share</a></li>
45  *                     </ul>
46  *             </div>
47  *      </div>
48 */
49
50 (function ( $, undefined ) {
51
52         $.widget( "tizen.tabbar", $.mobile.widget, {
53                 options: {
54                         iconpos: "top",
55                         grid: null,
56                         defaultList : 4,
57                         initSelector: ":jqmData(role='tabbar')"
58                 },
59
60                 _create: function () {
61
62                         var $tabbar = this.element,
63                                 $tabbtns,
64                                 textpos,
65                                 iconpos,
66                                 theme = $.mobile.listview.prototype.options.theme,      /* Get current theme */
67                                 ww = window.innerWidth || $( window ).width(),
68                                 wh = window.innerHeight || $( window ).height(),
69                                 tabbarDividerLeft = "<div class='ui-tabbar-divider ui-tabbar-divider-left'></div>",
70                                 tabbarDividerRight = "<div class='ui-tabbar-divider ui-tabbar-divider-right'></div>",
71                                 isLandscape;
72
73                         isLandscape = ww > wh && ( ww - wh );
74
75                         if ( isLandscape ) {
76                                 $tabbar.removeClass( "ui-portrait-tabbar" ).addClass( "ui-landscape-tabbar" );
77                         } else {
78                                 $tabbar.removeClass( "ui-landscape-tabbar" ).addClass( "ui-portrait-tabbar" );
79                         }
80
81                         if ( $tabbar.find( "a" ).length ) {
82                                 $tabbtns = $tabbar.find( "a" );
83                                 iconpos = $tabbtns.filter( ":jqmData(icon)" ).length ? this.options.iconpos : undefined;
84                                 textpos = $tabbtns.html().length ? true : false;
85                         }
86
87                         if ( $tabbar.parents( ".ui-header" ).length && $tabbar.parents( ".ui-scrollview-view" ).length ) {
88                                 $tabbar.find( "li" ).addClass( "tabbar-scroll-li" );
89                                 $tabbar.find( "ul" ).addClass( "tabbar-scroll-ul" );
90
91                                 /* add shadow divider */
92                                 $( tabbarDividerLeft ).appendTo( $tabbar.parents( ".ui-scrollview-clip" ) );
93                                 $( tabbarDividerRight ).appendTo( $tabbar.parents( ".ui-scrollview-clip" ) );
94
95                                 $( ".ui-tabbar-divider-left" ).hide();
96                                 $( ".ui-tabbar-divider-right" ).hide();
97
98                                 /* add width calculation*/
99                                 if ( $tabbar.parents( ".ui-scrollview-view" ).data("default-list") ) {
100                                         this.options.defaultList = $tabbar.parents( ".ui-scrollview-view" ).data( "default-list" );
101                                 }
102                                 $tabbar.find( "li" ).css( "width", window.innerWidth / this.options.defaultList + "px" );
103                         } else {
104                                 if ( $tabbar.find( "ul" ).children().length ) {
105                                         $tabbar.addClass( "ui-navbar" )
106                                                 .find( "ul" )
107                                                 .grid( { grid: this.options.grid } );
108                                 }
109                         }
110
111                         if ( $tabbar.parents( ".ui-footer" ).length  ) {
112                                 $tabbar.find( "li" ).addClass( "ui-tab-btn-style" );
113                         }
114
115                         /* title tabbar */
116                         if ( $tabbar.siblings( ".ui-title" ).length ) {
117                                 $tabbar.parents( ".ui-header" ).addClass( "ui-title-tabbar" );
118                         }
119
120                         if ( !iconpos ) {
121                                 $tabbar.addClass( "ui-tabbar-noicons" );
122                         }
123                         if ( !textpos ) {
124                                 $tabbar.addClass( "ui-tabbar-notext" );
125                         }
126                         if ( textpos && iconpos ) {
127                                 $tabbar.parents( ".ui-header" ).addClass( "ui-title-tabbar-multiline" );
128                         }
129
130                         if ( $tabbar.find( "a" ).length ) {
131                                 $tabbtns.buttonMarkup({
132                                         corners:        false,
133                                         shadow:         false,
134                                         iconpos:        iconpos
135                                 });
136                         }
137
138                         if ( $tabbar.find( ".ui-state-persist" ).length ) {
139                                 $tabbar.addClass( "ui-tabbar-persist" );
140                         }
141
142                         $tabbar.delegate( "a", "vclick", function ( event ) {
143                                 $tabbtns.not( ".ui-state-persist" ).removeClass( $.mobile.activeBtnClass );
144                                 $( this ).addClass( $.mobile.activeBtnClass );
145                         });
146
147                         $tabbar.addClass( "ui-tabbar");
148
149                         $( document ).bind( "pagebeforeshow", function ( event, ui ) {
150                                 var footer_filter = $( event.target ).find( ":jqmData(role='footer')" ),
151                                         tabbar_filter = footer_filter.find( ":jqmData(role='tabbar')" ),
152                                         $elFooterMore = tabbar_filter.siblings( ":jqmData(icon='naviframe-more')" ),
153                                         $elFooterBack = tabbar_filter.siblings( ".ui-btn-back" );
154
155                                 footer_filter
156                                         .css( "position", "fixed" )
157                                         .css( "bottom", 0 )
158                                         .css( "height", tabbar_filter.height() );
159                                 if ( $elFooterMore.length ) {
160                                         tabbar_filter.addClass( "ui-tabbar-margin-more" );
161                                 }
162                                 if ( $elFooterBack.length ) {
163                                         tabbar_filter.addClass( "ui-tabbar-margin-back" );
164                                 }
165                         });
166
167                         $tabbar.bind( "touchstart vmousedown", function ( e ) {
168                                 var $tabbarScroll = $( e.target ).parents( ".ui-scrollview-view" );
169                                 if ( $tabbarScroll.offset() ) {
170                                         if ( $tabbarScroll.offset().left < 0 ) {
171                                                 $( ".ui-tabbar-divider-left" ).show();
172                                         } else {
173                                                 $( ".ui-tabbar-divider-left" ).hide();
174                                         }
175                                         if ( ( $tabbarScroll.width() - $tabbarScroll.parents( ".ui-scrollview-clip" ).width() ) ==  Math.abs( $tabbarScroll.offset().left ) ) {
176                                                 $( ".ui-tabbar-divider-right" ).hide();
177                                         } else {
178                                                 $( ".ui-tabbar-divider-right" ).show();
179                                         }
180                                 }
181                         });
182
183                         this._bindTabbarEvents();
184                         this._initTabbarAnimation();
185                 },
186
187                 _initTabbarAnimation: function () {
188                         var isScrollingStart = false,
189                                 isScrollingEnd = false;
190                         $( document ).bind( "scrollstart.tabbar", function ( e ) {
191                                 if ( $( e.target ).find( ".ui-tabbar" ).length ) {
192                                         isScrollingStart = true;
193                                         isScrollingEnd = false;
194                                 }
195                         });
196
197                         $( document ).bind( "scrollstop.tabbar", function ( e ) {
198                                 var $tabbarScrollview = $( e.target ),
199                                         $elTabbar = $( e.target ).find( ".ui-tabbar" ),
200                                         $elTabbarLI = $( e.target ).find( ".ui-tabbar li" ),
201                                         $minElement = $elTabbarLI.eq( 0 ),
202                                         minElementIndexVal,
203                                         minElementIndex = -1;
204
205                                 isScrollingEnd = true;
206                                 if ( $elTabbar.length && isScrollingStart == true ) {
207                                         minElementIndexVal = Math.abs( $elTabbarLI.eq( 0 ).offset().left );
208                                         $elTabbarLI.each( function ( i ) {
209                                                 var offset      = $elTabbarLI.eq( i ).offset();
210
211                                                 if ( Math.abs( offset.left ) < minElementIndexVal ) {
212                                                         minElementIndexVal = Math.abs( offset.left );
213                                                         minElementIndex = i;
214                                                         $minElement = $elTabbarLI.eq( i );
215                                                 }
216                                         });
217
218                                         if ( $tabbarScrollview.length && isScrollingStart == isScrollingEnd && minElementIndex != -1) {
219                                                 isScrollingStart = false;
220                                                 $tabbarScrollview.scrollview( "scrollTo", -( window.innerWidth / $elTabbar.data( "defaultList" ) * minElementIndex ) , 0, 357);
221                                         }
222                                 }
223
224                                 $( ".ui-tabbar-divider-left" ).hide();
225                                 $( ".ui-tabbar-divider-right" ).hide();
226                         });
227                 },
228
229                 _bindTabbarEvents: function () {
230                         var $tabbar = this.element;
231
232                         $( window ).bind( "orientationchange", function ( e, ui ) {
233                                 var ww = window.innerWidth || $( window ).width(),
234                                         wh = window.innerHeight || $( window ).height(),
235                                         isLandscape = ww > wh && ( ww - wh );
236
237                                 if ( isLandscape ) {
238                                         $tabbar.removeClass( "ui-portrait-tabbar" ).addClass( "ui-landscape-tabbar" );
239                                 } else {
240                                         $tabbar.removeClass( "ui-landscape-tabbar" ).addClass( "ui-portrait-tabbar" );
241                                 }
242                         });
243                 },
244
245                 _setDisabled: function ( value, cnt ) {
246                         this.element.find( "li" ).eq( cnt ).attr( "disabled", value );
247                         this.element.find( "li" ).eq( cnt ).attr( "aria-disabled", value );
248                 },
249
250                 disable: function ( cnt ) {
251                         this._setDisabled( true, cnt );
252                         this.element.find( "li" ).eq( cnt ).addClass( "ui-disabled" );
253                 },
254
255                 enable: function ( cnt ) {
256                         this._setDisabled( false, cnt );
257                         this.element.find( "li" ).eq( cnt ).removeClass( "ui-disabled" );
258                 }
259         });
260
261         //auto self-init widgets
262         $( document ).bind( "pagecreate create", function ( e ) {
263                 $( $.tizen.tabbar.prototype.options.initSelector, e.target ).tabbar();
264         });
265 }( jQuery ) );
266