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 * Author: Jinhyuk Jun <jinhyuk.jun@samsung.com>
26 (function ( $, undefined ) {
28 $.widget( "mobile.pagelayout", $.mobile.widget, {
30 visibleOnPageShow: true,
31 disablePageZoom: true,
32 transition: "slide", //can be none, fade, slide (slide maps to slideup or slidedown)
35 tapToggleBlacklist: "a, input, select, textarea, .ui-header-fixed, .ui-footer-fixed",
36 hideDuringFocus: "input, textarea, select",
37 updatePagePadding: true,
38 trackPersistentToolbars: true,
39 // Browser detection! Weeee, here we go...
40 // Unfortunately, position:fixed is costly, not to mention probably impossible, to feature-detect accurately.
41 // Some tests exist, but they currently return false results in critical devices and browsers, which could lead to a broken experience.
42 // Testing fixed positioning is also pretty obtrusive to page load, requiring injected elements and scrolling the window
43 // The following function serves to rule out some popular browsers with known fixed-positioning issues
44 // This is a plugin option like any other, so feel free to improve or overwrite it
45 supportBlacklist: function () {
47 ua = navigator.userAgent,
48 platform = navigator.platform,
49 // Rendering engine is Webkit, and capture major version
50 wkmatch = ua.match( /AppleWebKit\/([0-9]+)/ ),
51 wkversion = !!wkmatch && wkmatch[ 1 ],
52 ffmatch = ua.match( /Fennec\/([0-9]+)/ ),
53 ffversion = !!ffmatch && ffmatch[ 1 ],
54 operammobilematch = ua.match( /Opera Mobi\/([0-9]+)/ ),
55 omversion = !!operammobilematch && operammobilematch[ 1 ];
58 // iOS 4.3 and older : Platform is iPhone/Pad/Touch and Webkit version is less than 534 (ios5)
59 ( ( platform.indexOf( "iPhone" ) > -1 || platform.indexOf( "iPad" ) > -1 || platform.indexOf( "iPod" ) > -1 ) && wkversion && wkversion < 534 )
62 ( w.operamini && ({}).toString.call( w.operamini ) === "[object OperaMini]" )
64 ( operammobilematch && omversion < 7458 )
66 //Android lte 2.1: Platform is Android and Webkit version is less than 533 (Android 2.2)
67 ( ua.indexOf( "Android" ) > -1 && wkversion && wkversion < 533 )
69 // Firefox Mobile before 6.0 -
70 ( ffversion && ffversion < 6 )
73 ( "palmGetResource" in window && wkversion && wkversion < 534 )
76 ( ua.indexOf( "MeeGo" ) > -1 && ua.indexOf( "NokiaBrowser/8.5.0" ) > -1 )
83 initSelector: ":jqmData(role='content')"
86 _create: function () {
92 // Feature detecting support for
93 if ( o.supportBlacklist() ) {
98 self._addFixedClass();
99 self._addTransitionClass();
100 self._bindPageEvents();
103 self._bindContentControlEvents();
106 /* add minimum fixed css style to bar(header/footer) and content
107 * it need to update when core source modified(jquery.mobile.page.section.js)
108 * modified from core source cuz initSelector different */
109 _addFixedClass: function () {
113 $elHeader = $el.siblings( ":jqmData(role='header')" ),
114 $elFooter = $el.siblings( ":jqmData(role='footer')" ),
115 $elPage = $el.closest(".ui-page");
117 $elHeader.addClass( "ui-header-fixed" );
118 $elFooter.addClass( "ui-footer-fixed" );
120 // "fullscreen" overlay positioning
121 if ( o.fullscreen ) {
122 $elHeader.addClass( "ui-header-fullscreen" );
123 $elFooter.addClass( "ui-footer-fullscreen" );
125 .addClass( "ui-page-header-fullscreen" )
126 .addClass( "ui-page-footer-fullscreen" );
128 // If not fullscreen, add class to page to set top or bottom padding
129 $elPage.addClass( "ui-page-header-fixed" )
130 .addClass( "ui-page-footer-fixed" );
134 /* original core source(jquery.mobile.fixedToolbar.js)
136 _addTransitionClass: function () {
137 var tclass = this.options.transition;
139 if ( tclass && tclass !== "none" ) {
140 // use appropriate slide for header or footer
141 if ( tclass === "slide" ) {
142 tclass = this.element.is( ".ui-header" ) ? "slidedown" : "slideup";
145 this.element.addClass( tclass );
150 /* Set default page positon
151 * 1. add title style to header
152 * 2. Set default header/footer position */
153 setHeaderFooter: function ( event ) {
154 var $elPage = $( event.target ),
155 $elHeader = $elPage.find( ":jqmData(role='header')" ).length ? $elPage.find( ":jqmData(role='header')") : $elPage.siblings( ":jqmData(role='header')"),
156 $elFieldcontain = $elHeader.find( ":jqmData(role='fieldcontain')" ),
157 $elControlgroup = $elHeader.find( ":jqmData(role='controlgroup')" ),
158 $elContent = $elPage.find( ".ui-content" ),
160 $elFooter = $( document ).find( ":jqmData(role='footer')" ),
161 $elFooterGroup = $elFooter.find( ":jqmData(role='fieldcontain')" ),
165 if ( $elHeader.jqmData("position") == "fixed" || $.tizen.frameworkData.theme.match(/tizen/) || $elHeader.css("position") == "fixed" ) {
167 .css( "position", "fixed" )
168 .css( "top", "0px" );
171 /* set Title style */
172 if ( $elHeader.find("span.ui-title-text-sub").length ) {
173 $elHeader.addClass( "ui-title-multiline");
176 // divide content mode scrollview and non-scrollview
177 // recalculate content area when resize callback occur
178 if ( $.support.scrollview ) {
179 if ( $elHeader.css( "position" ) != "fixed" ) {
180 $elHeader.css( "position", "fixed" );
183 if ( $elHeader.css("position") != "fixed" ) {
184 $elHeader.css( "position", "relative" );
188 if ( $elFooterGroup.find( "div" ).is( ".ui-controlgroup-label" ) ) {
189 $elFooterGroup.find( "div.ui-controlgroup-label" ).remove();
193 _bindPageEvents: function () {
198 //page event bindings
199 // Fixed toolbars require page zoom to be disabled, otherwise usability issues crop up
200 // This method is meant to disable zoom while a fixed-positioned toolbar page is visible
201 $el.closest( ".ui-page" )
202 .bind( "pagebeforeshow", function ( event ) {
203 if ( o.disablePageZoom ) {
204 $.mobile.zoom.disable( true );
206 if ( !o.visibleOnPageShow ) {
209 self.setHeaderFooter( event );
210 self._setContentMinHeight( event );
212 .bind( "webkitAnimationStart animationstart updatelayout", function ( e, data ) {
214 if ( o.updatePagePadding ) {
215 self.updatePagePadding(thisPage);
216 self.updatePageLayout(data);
220 .bind( "pageshow", function ( event ) {
222 self.updatePagePadding(thisPage);
223 self._updateHeaderArea();
224 if ( o.updatePagePadding ) {
225 $( window ).bind( "throttledresize." + self.widgetName, function () {
226 self.updatePagePadding(thisPage);
228 self.updatePageLayout();
229 self._updateHeaderArea();
230 self._setContentMinHeight( event );
235 .bind( "pagebeforehide", function ( e, ui ) {
236 if ( o.disablePageZoom ) {
237 $.mobile.zoom.enable( true );
239 if ( o.updatePagePadding ) {
240 $( window ).unbind( "throttledresize." + self.widgetName );
243 if ( o.trackPersistentToolbars ) {
244 var thisFooter = $( ".ui-footer-fixed:jqmData(id)", this ),
245 thisHeader = $( ".ui-header-fixed:jqmData(id)", this ),
246 nextFooter = thisFooter.length && ui.nextPage && $( ".ui-footer-fixed:jqmData(id='" + thisFooter.jqmData( "id" ) + "')", ui.nextPage ),
247 nextHeader = thisHeader.length && ui.nextPage && $( ".ui-header-fixed:jqmData(id='" + thisHeader.jqmData( "id" ) + "')", ui.nextPage );
249 nextFooter = nextFooter || $();
251 if ( nextFooter.length || nextHeader.length ) {
253 nextFooter.add( nextHeader ).appendTo( $.mobile.pageContainer );
255 ui.nextPage.one( "pageshow", function () {
256 nextFooter.add( nextHeader ).appendTo( this );
262 window.addEventListener( "softkeyboardchange", function( e ) {
263 var $elFooter = $( ".ui-page-active .ui-footer" ),
266 if ( e.state == "on" ) {
268 } else if (e.state == "off") {
271 self.updatePagePadding( thisPage, e.state );
275 _bindContentControlEvents: function () {
280 $el.closest( ".ui-page" )
281 .bind( "pagebeforeshow", function ( event ) {
286 _setContentMinHeight : function ( event ) {
287 var $elPage = $( event.target ),
288 $elHeader = $elPage.find( ":jqmData(role='header')" ),
289 $elFooter = $elPage.find( ":jqmData(role='footer')" ),
290 $elContent = $elPage.find( ":jqmData(role='content')" );
292 $elContent.css( "min-height", window.innerHeight - $elHeader.height() - $elFooter.height() + "px" );
295 _updateHeaderArea : function () {
296 var $elPage = $( ".ui-page-active" ),
297 $elHeader = $elPage.find( ":jqmData(role='header')" ).length ? $elPage.find( ":jqmData(role='header')") : $elPage.siblings( ":jqmData(role='header')"),
298 headerBtnNum = $elHeader.children("a").length,
299 headerSrcNum = $elHeader.children("img").length;
301 $elHeader.find( "h1" ).css( "width", window.innerWidth - $elHeader.children( "a" ).width() * headerBtnNum - $elHeader.children( "a" ).width() / 4 - $elHeader.children( "img" ).width() * headerSrcNum * 4 );
302 /* add half width for default space between text and button, and img tag area is too narrow, so multiply three for img width*/
306 /* IME concenpt change after alpha2.0 */
307 /* _IMEShown : false,
308 _IMEindicatorHeight : window.outerHeight - window.innerHeight,
310 layoutPageIME: function () {
311 if ( $( document.activeElement ).is( "input" ) || $( document.activeElement ).is( "textarea" )
312 || $(".ui-page-active .ui-header .input-search-bar").length
313 || $(".ui-page-active .ui-content").find("input").length
314 || $(".ui-page-active .ui-content").find("textarea").length) {
316 if ( ( window.innerHeight + this._IMEindicatorHeight ) < window.outerHeight && window.innerWidth == window.outerWidth ) {
317 if ( this._IMEShown === false ) {
318 $( ".ui-page-active .ui-footer" ).hide();
319 this._IMEShown = true;
321 } else if ( ( window.innerHeight + this._IMEindicatorHeight ) >= window.outerHeight ) {
322 if ( this._IMEShown === true ) {
323 $( ".ui-page-active .ui-footer" ).show();
324 this._IMEShown = false;
328 if ( ( window.innerHeight + this._IMEindicatorHeight ) >= window.outerHeight ) {
329 if ( this._IMEShown === true ) {
330 $( ".ui-page-active .ui-footer" ).show();
331 this._IMEShown = false;
337 // This will set the content element's top or bottom padding equal to the toolbar's height
338 updatePagePadding: function ( tbPage, imestatus ) {
339 var $el = this.element,
340 header = $el.siblings( ".ui-header" ).length;
342 // This behavior only applies to "fixed", not "fullscreen"
343 if ( this.options.fullscreen && imestatus ) { return; }
345 tbPage = tbPage || $el.closest( ".ui-page" );
346 if ( imestatus == "on" ) {
347 $el.height( window.innerHeight - $el.siblings( ".ui-header" ).height() -
348 parseFloat( $el.css("padding-top") ) -
349 parseFloat( $el.css("padding-bottom") ) );
351 $( tbPage ).css( "padding-" + ( header ? "top" : "bottom" ), $el.siblings( ".ui-header" ).outerHeight() );
354 /* 1. Calculate and update content height */
355 updatePageLayout: function ( receiveType ) {
358 $elPage = $( document ).find( ".ui-page-active" ),
359 $elHeader = $elPage.find( ":jqmData(role='header')" ),
360 $elContent = $elPage.find( ":jqmData(role='content')" ),
361 resultContentHeight = 0,
362 resultFooterHeight = 0,
363 resultHeaderHeight = 0;
365 if ( $elPage.length ) {
366 $elFooter = $( document ).find( ".ui-page-active" ).find( ":jqmData(role='footer')" );
368 $elFooter = $( document ).find( ":jqmData(role='footer')" ).eq( 0 );
370 $elFooterControlbar = $elFooter.find( ".ui-navbar" );
372 // calculate footer height
373 resultFooterHeight = ( $elFooter.css( "display" ) == "none" ) ? 0 : $elFooter.height();
374 resultHeaderHeight = ( $elHeader.css( "display" ) == "none" ) ? 0 : $elHeader.height();
376 if (resultFooterHeight != 0 ) {
377 $elFooter.css( "bottom", 0 );
380 resultContentHeight = window.innerHeight - resultFooterHeight - resultHeaderHeight;
382 if ( $.support.scrollview ) {
383 if ( $elHeader.css("position") != "fixed" ) {
384 $elHeader.css( "position", "fixed" );
387 $elContent.height( resultContentHeight -
388 parseFloat( $elContent.css("padding-top") ) -
389 parseFloat( $elContent.css("padding-bottom") ) );
391 if ( $elHeader.css("position") != "fixed" ) {
392 $elHeader.css( "position", "relative" );
394 $elContent.height( resultContentHeight );
398 // check this line need
399 // because another style title will be not supported to updatePageLayout
401 // in case title changed
403 $elContent.css( "top", resultHeaderHeight + "px" );
407 _useTransition: function ( notransition ) {
408 var $win = $( window ),
410 scroll = $win.scrollTop(),
411 elHeight = $el.height(),
412 pHeight = $el.closest( ".ui-page" ).height(),
413 viewportHeight = $.mobile.getScreenHeight(),
414 tbtype = $el.is( ":jqmData(role='header')" ) ? "header" : "footer";
416 return !notransition &&
417 ( this.options.transition && this.options.transition !== "none" &&
419 ( tbtype === "header" && !this.options.fullscreen && scroll > elHeight ) ||
420 ( tbtype === "footer" && !this.options.fullscreen && scroll + viewportHeight < pHeight - elHeight )
421 ) || this.options.fullscreen
425 show: function ( notransition ) {
426 /* var hideClass = "ui-fixed-hidden",
429 if ( this._useTransition( notransition ) ){
431 .removeClass( "out " + hideClass )
435 $el.removeClass( hideClass );
437 this._visible = true;*/
440 hide: function ( notransition ) {
441 /* var hideClass = "ui-fixed-hidden",
443 // if it's a slide transition, our new transitions need the reverse class as well to slide outward
444 outclass = "out" + ( this.options.transition === "slide" ? " reverse" : "" );
446 if ( this._useTransition( notransition ) ){
448 .addClass( outclass )
450 .animationComplete( function () {
451 $el.addClass( hideClass ).removeClass( outclass );
455 $el.addClass( hideClass ).removeClass( outclass );
457 this._visible = false;*/
460 toggle: function () {
461 this[ this._visible ? "hide" : "show" ]();
464 /* support external api for adding backbutton via javascript */
465 /* backButton: function ( target, status ){
466 this._addBackbutton( target, "external" );
469 destroy: function () {
470 this.element.removeClass( "ui-header-fixed ui-footer-fixed ui-header-fullscreen ui-footer-fullscreen in out fade slidedown slideup ui-fixed-hidden" );
471 this.element.closest( ".ui-page" ).removeClass( "ui-page-header-fixed ui-page-footer-fixed ui-page-header-fullscreen ui-page-footer-fullscreen" );
476 //auto self-init widgets
478 .bind( "pagecreate create", function ( e ) {
479 // DEPRECATED in 1.1: support for data-fullscreen=true|false on the page element.
480 // This line ensures it still works, but we recommend moving the attribute to the toolbars themselves.
481 if ( $( e.target ).jqmData( "fullscreen" ) ) {
482 $( $.mobile.pagelayout.prototype.options.initSelector, e.target ).not( ":jqmData(fullscreen)" ).jqmData( "fullscreen", true );
484 $.mobile.pagelayout.prototype.enhanceWithin( e.target );