1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Set a layout of pages
4 //>>group: Tizen:Widgets
6 define( [ '../jquery.mobile.tizen.core' ], 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 * Author: Jinhyuk Jun <jinhyuk.jun@samsung.com>
34 (function ( $, undefined ) {
36 $.widget( "mobile.pagelayout", $.mobile.widget, {
38 visibleOnPageShow: true,
39 disablePageZoom: true,
40 transition: "slide", //can be none, fade, slide (slide maps to slideup or slidedown)
43 tapToggleBlacklist: "a, input, select, textarea, .ui-header-fixed, .ui-footer-fixed",
44 hideDuringFocus: "input, textarea, select",
45 updatePagePadding: true,
46 trackPersistentToolbars: true,
47 // Browser detection! Weeee, here we go...
48 // Unfortunately, position:fixed is costly, not to mention probably impossible, to feature-detect accurately.
49 // Some tests exist, but they currently return false results in critical devices and browsers, which could lead to a broken experience.
50 // Testing fixed positioning is also pretty obtrusive to page load, requiring injected elements and scrolling the window
51 // The following function serves to rule out some popular browsers with known fixed-positioning issues
52 // This is a plugin option like any other, so feel free to improve or overwrite it
53 supportBlacklist: function () {
55 ua = navigator.userAgent,
56 platform = navigator.platform,
57 // Rendering engine is Webkit, and capture major version
58 wkmatch = ua.match( /AppleWebKit\/([0-9]+)/ ),
59 wkversion = !!wkmatch && wkmatch[ 1 ],
60 ffmatch = ua.match( /Fennec\/([0-9]+)/ ),
61 ffversion = !!ffmatch && ffmatch[ 1 ],
62 operammobilematch = ua.match( /Opera Mobi\/([0-9]+)/ ),
63 omversion = !!operammobilematch && operammobilematch[ 1 ];
66 // iOS 4.3 and older : Platform is iPhone/Pad/Touch and Webkit version is less than 534 (ios5)
67 ( ( platform.indexOf( "iPhone" ) > -1 || platform.indexOf( "iPad" ) > -1 || platform.indexOf( "iPod" ) > -1 ) && wkversion && wkversion < 534 ) ||
69 ( w.operamini && ({}).toString.call( w.operamini ) === "[object OperaMini]" ) ||
70 ( operammobilematch && omversion < 7458 ) ||
71 //Android lte 2.1: Platform is Android and Webkit version is less than 533 (Android 2.2)
72 ( ua.indexOf( "Android" ) > -1 && wkversion && wkversion < 533 ) ||
73 // Firefox Mobile before 6.0 -
74 ( ffversion && ffversion < 6 ) ||
76 ( window.palmGetResource !== undefined && wkversion && wkversion < 534 ) ||
78 ( ua.indexOf( "MeeGo" ) > -1 && ua.indexOf( "NokiaBrowser/8.5.0" ) > -1 )
85 initSelector: ":jqmData(role='content')"
88 _create: function () {
94 // Feature detecting support for
95 if ( o.supportBlacklist() ) {
100 self._addFixedClass();
101 self._addTransitionClass();
102 self._bindPageEvents();
105 self._bindContentControlEvents();
108 /* add minimum fixed css style to bar(header/footer) and content
109 * it need to update when core source modified(jquery.mobile.page.section.js)
110 * modified from core source cuz initSelector different */
111 _addFixedClass: function () {
115 $elHeader = $el.siblings( ":jqmData(role='header')" ),
116 $elFooter = $el.siblings( ":jqmData(role='footer')" ),
117 $elPage = $el.closest(".ui-page");
119 $elHeader.addClass( "ui-header-fixed" );
120 $elFooter.addClass( "ui-footer-fixed" );
122 // "fullscreen" overlay positioning
123 if ( o.fullscreen ) {
124 $elHeader.addClass( "ui-header-fullscreen" );
125 $elFooter.addClass( "ui-footer-fullscreen" );
127 .addClass( "ui-page-header-fullscreen" )
128 .addClass( "ui-page-footer-fullscreen" );
130 // If not fullscreen, add class to page to set top or bottom padding
131 $elPage.addClass( "ui-page-header-fixed" )
132 .addClass( "ui-page-footer-fixed" );
136 /* original core source(jquery.mobile.fixedToolbar.js)
138 _addTransitionClass: function () {
139 var tclass = this.options.transition;
141 if ( tclass && tclass !== "none" ) {
142 // use appropriate slide for header or footer
143 if ( tclass === "slide" ) {
144 tclass = this.element.is( ".ui-header" ) ? "slidedown" : "slideup";
147 this.element.addClass( tclass );
152 /* Set default page positon
153 * 1. add title style to header
154 * 2. Set default header/footer position */
155 setHeaderFooter: function ( thisPage ) {
156 var $elPage = $( thisPage ),
157 $elHeader = $elPage.find( ":jqmData(role='header')" ).length ? $elPage.find( ":jqmData(role='header')") : $elPage.siblings( ":jqmData(role='header')"),
158 $elContent = $elPage.find( ".ui-content" ),
159 $elFooter = $elPage.find( ":jqmData(role='footer')" ),
160 $elFooterGroup = $elFooter.find( ":jqmData(role='fieldcontain')" ),
161 $elFooterControlGroup = $elFooter.find( ".ui-controlgroup" );
163 // divide content mode scrollview and non-scrollview
164 if ( !$elPage.is( ".ui-dialog" ) ) {
165 if ( $elHeader.jqmData("position") == "fixed" || ( $.support.scrollview && $.tizen.frameworkData.theme.match(/tizen/) ) ) {
167 .css( "position", "fixed" )
168 .css( "top", "0px" );
169 } else if ( !$.support.scrollview && $elHeader.jqmData("position") != "fixed" ) {
170 $elHeader.css( "position", "relative" );
174 /* set Title style */
175 if ( $elHeader.find("span.ui-title-text-sub").length ) {
176 $elHeader.addClass( "ui-title-multiline");
179 if ( $elFooterGroup.find( "div" ).is( ".ui-controlgroup-label" ) ) {
180 $elFooterGroup.find( "div.ui-controlgroup-label" ).remove();
183 if ( $elFooterControlGroup.length ) {
184 var anchorPer = 100 / $elFooterControlGroup.find( "a" ).length;
185 $elFooterControlGroup.find( "a" ).each( function ( i ) {
186 $elFooterControlGroup.find( "a" ).eq( i ).width( anchorPer + "%" );
191 _bindPageEvents: function () {
197 //page event bindings
198 // Fixed toolbars require page zoom to be disabled, otherwise usability issues crop up
199 // This method is meant to disable zoom while a fixed-positioned toolbar page is visible
200 $el.closest( ".ui-page" )
201 .bind( "pagebeforeshow", function ( event ) {
203 if ( o.disablePageZoom ) {
204 $.mobile.zoom.disable( true );
206 if ( !o.visibleOnPageShow ) {
209 self.setHeaderFooter( thisPage );
210 self._setContentMinHeight( thisPage );
212 .bind( "webkitAnimationStart animationstart updatelayout", function ( e, data ) {
214 if ( o.updatePagePadding ) {
215 self.updatePagePadding(thisPage);
216 self.updatePageLayout( thisPage, data);
220 .bind( "pageshow", function ( event ) {
222 self._setContentMinHeight( thisPage );
223 self.updatePagePadding( thisPage );
224 self._updateHeaderArea( thisPage );
225 if ( o.updatePagePadding ) {
226 $( window ).bind( "throttledresize." + self.widgetName, function () {
227 self.updatePagePadding(thisPage);
229 self.updatePageLayout( thisPage, false);
230 self._updateHeaderArea( thisPage );
231 self._setContentMinHeight( thisPage );
236 .bind( "pagebeforehide", function ( e, ui ) {
237 if ( o.disablePageZoom ) {
238 $.mobile.zoom.enable( true );
240 if ( o.updatePagePadding ) {
241 $( window ).unbind( "throttledresize." + self.widgetName );
244 if ( o.trackPersistentToolbars ) {
245 var thisFooter = $( ".ui-footer-fixed:jqmData(id)", this ),
246 thisHeader = $( ".ui-header-fixed:jqmData(id)", this ),
247 nextFooter = thisFooter.length && ui.nextPage && $( ".ui-footer-fixed:jqmData(id='" + thisFooter.jqmData( "id" ) + "')", ui.nextPage ),
248 nextHeader = thisHeader.length && ui.nextPage && $( ".ui-header-fixed:jqmData(id='" + thisHeader.jqmData( "id" ) + "')", ui.nextPage );
250 nextFooter = nextFooter || $();
252 if ( nextFooter.length || nextHeader.length ) {
254 nextFooter.add( nextHeader ).appendTo( $.mobile.pageContainer );
256 ui.nextPage.one( "pageshow", function () {
257 nextFooter.add( nextHeader ).appendTo( this );
263 window.addEventListener( "softkeyboardchange", function ( e ) {
264 var thisPage = $( ".ui-page-active" );
266 if ( e.state == "on" ) {
267 $elCurrentFooter = $( ".ui-page-active .ui-footer" );
268 $elCurrentFooter.hide();
269 } else if (e.state == "off") {
270 $elCurrentFooter.show();
272 self.updatePagePadding( thisPage );
273 self.updatePageLayout( thisPage, true );
277 _bindContentControlEvents: function () {
282 $el.closest( ".ui-page" )
283 .bind( "pagebeforeshow", function ( event ) {
288 _setContentMinHeight : function ( thisPage ) {
289 var $elPage = $( thisPage ),
290 $elHeader = $elPage.find( ":jqmData(role='header')" ),
291 $elFooter = $elPage.find( ":jqmData(role='footer')" ),
292 $elContent = $elPage.find( ":jqmData(role='content')" ),
295 resultMinHeight = window.innerHeight - $elHeader.height() - $elFooter.height();
297 $elContent.css( "min-height", resultMinHeight - parseFloat( $elContent.css("padding-top") ) - parseFloat( $elContent.css("padding-bottom") ) + "px" );
300 _updateHeaderArea : function ( thisPage ) {
301 var $elPage = $( thisPage ),
302 $elHeader = $elPage.find( ":jqmData(role='header')" ).length ? $elPage.find( ":jqmData(role='header')") : $elPage.siblings( ":jqmData(role='header')"),
303 headerBtnNum = $elHeader.children("a").length,
304 headerSrcNum = $elHeader.children("img").length;
306 if ( !$elPage.is( ".ui-dialog" ) ) {
307 $elHeader.find( "h1" ).css( "width", window.innerWidth - parseInt( $elHeader.find( "h1" ).css( "margin-left" ), 10 ) * 2 - $elHeader.children( "a" ).width() * headerBtnNum - $elHeader.children( "a" ).width() / 4 - $elHeader.children( "img" ).width() * headerSrcNum * 4 );
309 /* add half width for default space between text and button, and img tag area is too narrow, so multiply three for img width*/
314 // This will set the content element's top or bottom padding equal to the toolbar's height
315 updatePagePadding: function ( tbPage ) {
316 var $el = this.element,
317 header = $el.siblings( ".ui-header" ).length,
318 footer = $el.siblings( ".ui-footer" ).length;
320 // This behavior only applies to "fixed", not "fullscreen"
321 if ( this.options.fullscreen ) {
325 tbPage = tbPage || $el.closest( ".ui-page" );
327 if ( $el.siblings( ".ui-header" ).jqmData("position") == "fixed" || $.support.scrollview ) {
328 $( tbPage ).css( "padding-top", ( header ? $el.siblings( ".ui-header" ).outerHeight() : 0 ) );
330 $( tbPage ).css( "padding-bottom", ( footer ? $el.siblings( ".ui-footer" ).outerHeight() : 0 ) );
333 /* 1. Calculate and update content height */
334 updatePageLayout: function ( thisPage, receiveType ) {
336 $elPage = $( thisPage ),
337 $elHeader = $elPage.find( ":jqmData(role='header')" ),
338 $elContent = $elPage.find( ":jqmData(role='content')" ),
339 resultContentHeight = 0,
340 resultFooterHeight = 0,
341 resultHeaderHeight = 0;
343 if ( $elPage.length ) {
344 $elFooter = $elPage.find( ":jqmData(role='footer')" );
346 $elFooter = $( document ).find( ":jqmData(role='footer')" ).eq( 0 );
349 // calculate footer height
350 resultFooterHeight = ( $elFooter.css( "display" ) == "none" || $elFooter.length == 0 ) ? 0 : $elFooter.height();
351 resultHeaderHeight = ( $elHeader.css( "display" ) == "none" || $elHeader.length == 0 ) ? 0 : $elHeader.height();
353 if (resultFooterHeight != 0 ) {
354 $elFooter.css( "bottom", 0 );
357 resultContentHeight = window.innerHeight - resultFooterHeight - resultHeaderHeight;
359 if ( $.support.scrollview ) {
360 $elContent.height( resultContentHeight -
361 parseFloat( $elContent.css("padding-top") ) -
362 parseFloat( $elContent.css("padding-bottom") ) );
365 // External call page( "refresh") - in case title changed
368 .css( "min-height", resultContentHeight )
369 .css( "padding-top", resultHeaderHeight )
370 .css( "padding-bottom", resultFooterHeight );
374 show: function ( notransition ) {
375 /* blank function: deprecated */
378 hide: function ( notransition ) {
379 /* blank function: deprecated */
382 toggle: function () {
383 this[ this._visible ? "hide" : "show" ]();
386 destroy: function () {
387 this.element.removeClass( "ui-header-fixed ui-footer-fixed ui-header-fullscreen ui-footer-fullscreen in out fade slidedown slideup ui-fixed-hidden" );
388 this.element.closest( ".ui-page" ).removeClass( "ui-page-header-fixed ui-page-footer-fixed ui-page-header-fullscreen ui-page-footer-fullscreen" );
392 //auto self-init widgets
394 .bind( "pagecreate create", function ( e ) {
395 // DEPRECATED in 1.1: support for data-fullscreen=true|false on the page element.
396 // This line ensures it still works, but we recommend moving the attribute to the toolbars themselves.
397 if ( $( e.target ).jqmData( "fullscreen" ) ) {
398 $( $.mobile.pagelayout.prototype.options.initSelector, e.target ).not( ":jqmData(fullscreen)" ).jqmData( "fullscreen", true );
400 $.mobile.pagelayout.prototype.enhanceWithin( e.target );
405 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
407 //>>excludeEnd("jqmBuildExclude");