1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Shows buttons divided automatically on the header
4 //>>group: Tizen:Widgets
6 define( [ '../jquery.mobile.tizen.core', 'jquery.mobile.tizen.pagelayout' ], function ( ) {
7 //>>excludeEnd("jqmBuildExclude");
9 /* ***************************************************************************
10 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 * ***************************************************************************
31 * jQuery Mobile Framework : "tabbar" plugin
32 * Copyright (c) jQuery Project
33 * Dual licensed under the MIT or GPL Version 2 licenses.
34 * http://jquery.org/license
35 * Authors: Jinhyuk Jun <jinhyuk.jun@samsung.com>
39 * Tabbar can be created using data-role = "tabbar" inside footer
40 * Framework determine which tabbar will display with tabbar attribute
44 * HTML markup for creating tabbar: ( 2 ~ 5 li item available )
45 * icon can be changed data-icon attribute (customized icon need)
46 * <div data-role="footer" data-position ="fixed">
47 * <div data-role="tabbar">
49 * <li><a href="#" class="ui-btn-active">Menu</a></li>
50 * <li><a href="#">Save</a></li>
51 * <li><a href="#">Share</a></li>
57 (function ( $, undefined ) {
59 $.widget( "tizen.tabbar", $.mobile.widget, {
64 initSelector: ":jqmData(role='tabbar')"
67 _create: function () {
69 var $tabbar = this.element,
73 theme = $.mobile.listview.prototype.options.theme, /* Get current theme */
74 ww = window.innerWidth || $( window ).width(),
75 wh = window.innerHeight || $( window ).height(),
76 tabbarDividerLeft = "<div class='ui-tabbar-divider ui-tabbar-divider-left'></div>",
77 tabbarDividerRight = "<div class='ui-tabbar-divider ui-tabbar-divider-right'></div>",
78 isScrollingStart = false,
79 isScrollingEnd = false,
82 isLandscape = ww > wh && ( ww - wh );
85 $tabbar.removeClass( "ui-portrait-tabbar" ).addClass( "ui-landscape-tabbar" );
87 $tabbar.removeClass( "ui-landscape-tabbar" ).addClass( "ui-portrait-tabbar" );
90 if ( $tabbar.find( "a" ).length ) {
91 $tabbtns = $tabbar.find( "a" );
92 iconpos = $tabbtns.filter( ":jqmData(icon)" ).length ? this.options.iconpos : undefined;
93 textpos = $tabbtns.html().length ? true : false;
96 if ( $tabbar.parents( ".ui-header" ).length && $tabbar.parents( ".ui-scrollview-view" ).length ) {
97 $tabbar.find( "li" ).addClass( "tabbar-scroll-li" );
98 $tabbar.find( "ul" ).addClass( "tabbar-scroll-ul" );
100 /* add shadow divider */
101 $( tabbarDividerLeft ).appendTo( $tabbar.parents( ".ui-scrollview-clip" ) );
102 $( tabbarDividerRight ).appendTo( $tabbar.parents( ".ui-scrollview-clip" ) );
104 $( ".ui-tabbar-divider-left" ).hide();
105 $( ".ui-tabbar-divider-right" ).hide();
107 /* add width calculation*/
108 if ( $tabbar.parents( ".ui-scrollview-view" ).data("default-list") ) {
109 this.options.defaultList = $tabbar.parents( ".ui-scrollview-view" ).data( "default-list" );
111 $tabbar.find( "li" ).css( "width", window.innerWidth / this.options.defaultList + "px" );
113 if ( $tabbar.find( "ul" ).children().length ) {
114 $tabbar.addClass( "ui-navbar" )
116 .grid( { grid: this.options.grid } );
120 if ( $tabbar.parents( ".ui-footer" ).length ) {
121 $tabbar.find( "li" ).addClass( "ui-tab-btn-style" );
125 if ( $tabbar.siblings( ".ui-title" ).length ) {
126 $tabbar.parents( ".ui-header" ).addClass( "ui-title-tabbar" );
130 $tabbar.addClass( "ui-tabbar-noicons" );
133 $tabbar.addClass( "ui-tabbar-notext" );
135 if ( textpos && iconpos ) {
136 $tabbar.parents( ".ui-header" ).addClass( "ui-title-tabbar-multiline" );
139 if ( $tabbar.find( "a" ).length ) {
140 $tabbtns.buttonMarkup({
147 if ( $tabbar.find( ".ui-state-persist" ).length ) {
148 $tabbar.addClass( "ui-tabbar-persist" );
151 $tabbar.delegate( "a", "vclick", function ( event ) {
152 $tabbtns.not( ".ui-state-persist" ).removeClass( $.mobile.activeBtnClass );
153 $( this ).addClass( $.mobile.activeBtnClass );
156 $tabbar.addClass( "ui-tabbar");
158 $( document ).bind( "pagebeforeshow", function ( event, ui ) {
159 var footer_filter = $( event.target ).find( ":jqmData(role='footer')" ),
160 tabbar_filter = footer_filter.find( ":jqmData(role='tabbar')" ),
161 $elFooterMore = tabbar_filter.siblings( ":jqmData(icon='naviframe-more')" ),
162 $elFooterBack = tabbar_filter.siblings( ".ui-btn-back" );
165 .css( "position", "fixed" )
167 .css( "height", tabbar_filter.height() );
168 if ( $elFooterMore.length ) {
169 tabbar_filter.addClass( "ui-tabbar-margin-more" );
171 if ( $elFooterBack.length ) {
172 tabbar_filter.addClass( "ui-tabbar-margin-back" );
175 isScrollingStart = false;
178 $( window ).bind( "tabbar.scrollstart", function ( e ) {
179 if ( $( e.target ).find( ".ui-tabbar" ).length ) {
180 isScrollingStart = true;
181 isScrollingEnd = false;
185 $( window ).bind( "tabbar.scrollstop", function ( e ) {
186 var $tabbarScrollview = $( e.target ),
187 $minElement = $tabbar.find( "li" ).eq( 0 ),
188 minElementIndexVal = Math.abs( $tabbar.find( "li" ).eq( 0 ).offset().left ),
189 minElementIndex = -1;
191 isScrollingEnd = true;
192 if ( $( e.target ).find( ".ui-tabbar" ).length && isScrollingStart == true ) {
193 $tabbar.find( "li" ).each( function ( i ) {
194 var offset = $tabbar.find( "li" ).eq( i ).offset();
195 if ( Math.abs( offset.left ) < minElementIndexVal ) {
196 minElementIndexVal = Math.abs( offset.left );
198 $minElement = $tabbar.find( "li" ).eq( i );
202 if ( $tabbarScrollview.length && isScrollingStart == isScrollingEnd && minElementIndex != -1) {
203 isScrollingStart = false;
204 $tabbarScrollview.scrollview( "scrollTo", -( window.innerWidth / $( e.target ).find( ".ui-tabbar" ).data( "defaultList" ) * minElementIndex ) , 0, 357);
208 $( ".ui-tabbar-divider-left" ).hide();
209 $( ".ui-tabbar-divider-right" ).hide();
212 $tabbar.bind( "touchstart vmousedown", function ( e ) {
213 var $tabbarScroll = $( e.target ).parents( ".ui-scrollview-view" );
214 if ( $tabbarScroll.offset() ) {
215 if ( $tabbarScroll.offset().left < 0 ) {
216 $( ".ui-tabbar-divider-left" ).show();
218 $( ".ui-tabbar-divider-left" ).hide();
220 if ( ( $tabbarScroll.width() - $tabbarScroll.parents( ".ui-scrollview-clip" ).width() ) == Math.abs( $tabbarScroll.offset().left ) ) {
221 $( ".ui-tabbar-divider-right" ).hide();
223 $( ".ui-tabbar-divider-right" ).show();
228 this._bindTabbarEvents();
231 _bindTabbarEvents: function () {
232 var $tabbar = this.element;
234 $( window ).bind( "orientationchange", function ( e, ui ) {
235 var ww = window.innerWidth || $( window ).width(),
236 wh = window.innerHeight || $( window ).height(),
237 isLandscape = ww > wh && ( ww - wh );
240 $tabbar.removeClass( "ui-portrait-tabbar" ).addClass( "ui-landscape-tabbar" );
242 $tabbar.removeClass( "ui-landscape-tabbar" ).addClass( "ui-portrait-tabbar" );
247 _setDisabled: function ( value, cnt ) {
248 this.element.find( "li" ).eq( cnt ).attr( "disabled", value );
249 this.element.find( "li" ).eq( cnt ).attr( "aria-disabled", value );
252 disable: function ( cnt ) {
253 this._setDisabled( true, cnt );
254 this.element.find( "li" ).eq( cnt ).addClass( "ui-disabled" );
257 enable: function ( cnt ) {
258 this._setDisabled( false, cnt );
259 this.element.find( "li" ).eq( cnt ).removeClass( "ui-disabled" );
263 //auto self-init widgets
264 $( document ).bind( "pagecreate create", function ( e ) {
265 $( $.tizen.tabbar.prototype.options.initSelector, e.target ).tabbar();
269 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
271 //>>excludeEnd("jqmBuildExclude");