1 /* ***************************************************************************
2 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 * ***************************************************************************
23 * jQuery Mobile Framework : "tabbar" plugin
24 * Copyright (c) jQuery Project
25 * Dual licensed under the MIT or GPL Version 2 licenses.
26 * http://jquery.org/license
27 * Authors: Jinhyuk Jun <jinhyuk.jun@samsung.com>
31 * Tabbar can be created using data-role = "tabbar" inside footer
32 * Framework determine which tabbar will display with tabbar attribute
36 * HTML markup for creating tabbar: ( 2 ~ 5 li item available )
37 * icon can be changed data-icon attribute (customized icon need)
38 * <div data-role="footer" data-position ="fixed">
39 * <div data-role="tabbar">
41 * <li><a href="#" class="ui-btn-active">Menu</a></li>
42 * <li><a href="#">Save</a></li>
43 * <li><a href="#">Share</a></li>
49 (function ( $, undefined ) {
51 $.widget( "tizen.tabbar", $.mobile.widget, {
56 initSelector: ":jqmData(role='tabbar')"
59 _create: function () {
61 var $tabbar = this.element,
65 theme = $.mobile.listview.prototype.options.theme, /* Get current theme */
66 ww = window.innerWidth || $( window ).width(),
67 wh = window.innerHeight || $( window ).height(),
68 tabbarDividerLeft = "<div class='ui-tabbar-divider ui-tabbar-divider-left'></div>",
69 tabbarDividerRight = "<div class='ui-tabbar-divider ui-tabbar-divider-right'></div>",
70 isScrollingStart = false,
71 isScrollingEnd = false,
74 isLandscape = ww > wh && ( ww - wh );
77 $tabbar.removeClass( "ui-portrait-tabbar" ).addClass( "ui-landscape-tabbar" );
79 $tabbar.removeClass( "ui-landscape-tabbar" ).addClass( "ui-portrait-tabbar" );
82 if ( $tabbar.find( "a" ).length ) {
83 $tabbtns = $tabbar.find( "a" );
84 iconpos = $tabbtns.filter( ":jqmData(icon)" ).length ? this.options.iconpos : undefined;
85 textpos = $tabbtns.html().length ? true : false;
88 if ( $tabbar.parents( ".ui-header" ).length && $tabbar.parents( ".ui-scrollview-view" ).length ) {
89 $tabbar.find( "li" ).addClass( "tabbar-scroll-li" );
90 $tabbar.find( "ul" ).addClass( "tabbar-scroll-ul" );
92 /* add shadow divider */
93 $( tabbarDividerLeft ).appendTo( $tabbar.parents( ".ui-scrollview-clip" ) );
94 $( tabbarDividerRight ).appendTo( $tabbar.parents( ".ui-scrollview-clip" ) );
96 $( ".ui-tabbar-divider-left" ).hide();
97 $( ".ui-tabbar-divider-right" ).hide();
99 /* add width calculation*/
100 if ( $tabbar.parents( ".ui-scrollview-view" ).data("default-list") ) {
101 this.options.defaultList = $tabbar.parents( ".ui-scrollview-view" ).data( "default-list" );
103 $tabbar.find( "li" ).css( "width", window.innerWidth / this.options.defaultList + "px" );
105 if ( $tabbar.find( "ul" ).children().length ) {
106 $tabbar.addClass( "ui-navbar" )
108 .grid( { grid: this.options.grid } );
112 if ( $tabbar.parents( ".ui-footer" ).length ) {
113 $tabbar.find( "li" ).addClass( "ui-tab-btn-style" );
117 if ( $tabbar.siblings( ".ui-title" ).length ) {
118 $tabbar.parents( ".ui-header" ).addClass( "ui-title-tabbar" );
122 $tabbar.addClass( "ui-tabbar-noicons" );
125 $tabbar.addClass( "ui-tabbar-notext" );
127 if ( textpos && iconpos ) {
128 $tabbar.parents( ".ui-header" ).addClass( "ui-title-tabbar-multiline" );
131 if ( $tabbar.find( "a" ).length ) {
132 $tabbtns.buttonMarkup({
139 if ( $tabbar.find( ".ui-state-persist" ).length ) {
140 $tabbar.addClass( "ui-tabbar-persist" );
143 $tabbar.delegate( "a", "vclick", function ( event ) {
144 $tabbtns.not( ".ui-state-persist" ).removeClass( $.mobile.activeBtnClass );
145 $( this ).addClass( $.mobile.activeBtnClass );
148 $tabbar.addClass( "ui-tabbar");
150 $( document ).bind( "pagebeforeshow", function ( event, ui ) {
151 var footer_filter = $( event.target ).find( ":jqmData(role='footer')" ),
152 tabbar_filter = footer_filter.find( ":jqmData(role='tabbar')" ),
153 $elFooterMore = tabbar_filter.siblings( ":jqmData(icon='naviframe-more')" ),
154 $elFooterBack = tabbar_filter.siblings( ".ui-btn-back" );
157 .css( "position", "fixed" )
159 .css( "height", tabbar_filter.height() );
160 if ( $elFooterMore.length )
161 tabbar_filter.addClass( "ui-tabbar-margin-more" );
162 if ( $elFooterBack.length )
163 tabbar_filter.addClass( "ui-tabbar-margin-back" );
165 isScrollingStart = false;
168 $( window ).bind( "tabbar.scrollstart", function ( e ) {
169 if ( $( e.target ).find( ".ui-tabbar" ).length ) {
170 isScrollingStart = true;
171 isScrollingEnd = false;
175 $( window ).bind( "tabbar.scrollstop", function ( e ) {
176 var $tabbarScrollview = $( e.target ),
177 $minElement = $tabbar.find( "li" ).eq( 0 ),
178 minElementIndexVal = Math.abs( $tabbar.find( "li" ).eq( 0 ).offset().left ),
179 minElementIndex = -1;
181 isScrollingEnd = true;
182 if ( $( e.target ).find( ".ui-tabbar" ).length && isScrollingStart == true ) {
183 $tabbar.find( "li" ).each( function ( i ) {
184 var offset = $tabbar.find( "li" ).eq( i ).offset();
185 if ( Math.abs( offset.left ) < minElementIndexVal ) {
186 minElementIndexVal = Math.abs( offset.left );
188 $minElement = $tabbar.find( "li" ).eq( i );
192 if ( $tabbarScrollview.length && isScrollingStart == isScrollingEnd && minElementIndex != -1) {
193 isScrollingStart = false;
195 $tabbarScrollview.scrollview( "scrollTo", -( window.innerWidth / $( e.target ).find( ".ui-tabbar" ).data( "defaultList" ) * minElementIndex ) , 0, 357);
199 $( ".ui-tabbar-divider-left" ).hide();
200 $( ".ui-tabbar-divider-right" ).hide();
203 $tabbar.bind( "touchstart vmousedown", function ( e ) {
204 var $tabbarScroll = $( e.target ).parents( ".ui-scrollview-view" );
205 if ( $tabbarScroll.offset() ) {
206 $tabbarScroll.offset().left < 0 ?
207 $( ".ui-tabbar-divider-left" ).show() : $( ".ui-tabbar-divider-left" ).hide();
208 ( $tabbarScroll.width() - $tabbarScroll.parents( ".ui-scrollview-clip" ).width() ) == Math.abs( $tabbarScroll.offset().left ) ?
209 $( ".ui-tabbar-divider-right" ).hide() : $( ".ui-tabbar-divider-right" ).show();
213 this._bindTabbarEvents();
216 _bindTabbarEvents: function () {
217 var $tabbar = this.element;
219 $( window ).bind( "orientationchange", function ( e, ui ) {
220 var ww = window.innerWidth || $( window ).width(),
221 wh = window.innerHeight || $( window ).height(),
222 isLandscape = ww > wh && ( ww - wh );
225 $tabbar.removeClass( "ui-portrait-tabbar" ).addClass( "ui-landscape-tabbar" );
227 $tabbar.removeClass( "ui-landscape-tabbar" ).addClass( "ui-portrait-tabbar" );
232 _setDisabled: function ( value, cnt ) {
233 this.element.find( "li" ).eq( cnt ).attr( "disabled", value );
234 this.element.find( "li" ).eq( cnt ).attr( "aria-disabled", value );
237 disable: function ( cnt ) {
238 this._setDisabled( true, cnt );
239 this.element.find( "li" ).eq( cnt ).addClass( "ui-disabled" );
242 enable: function ( cnt ) {
243 this._setDisabled( false, cnt );
244 this.element.find( "li" ).eq( cnt ).removeClass( "ui-disabled" );
248 //auto self-init widgets
249 $( document ).bind( "pagecreate create", function ( e ) {
250 $( $.tizen.tabbar.prototype.options.initSelector, e.target ).tabbar();