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" ),
167 if ( $elFieldcontain.length != 0 || $elControlgroup.length != 0 ) {
171 if ( $elHeader.jqmData("position") == "fixed" || $.tizen.frameworkData.theme.match(/tizen/) || $elHeader.css("position") == "fixed" ) {
173 .css( "position", "fixed" )
174 .css( "top", "0px" );
176 if ( $elHeader.is(".ui-title-controlbar-multiline") ) {
177 $( event.target ).find( ".ui-content" ).addClass( "ui-title-content-multi-controlbar-height" );
179 if ( $elHeader.length ) {
180 $( event.target ).find( ".ui-content" ).addClass( "ui-title-content-" + tStyle + "-height" );
182 $( event.target ).find( ".ui-content" ).addClass( "ui-title-content-no-height" );
187 /* set Title style */
189 if ( $elHeader.find("span.ui-title-text-sub").length ) {
190 $elHeader.addClass( "ui-title-multiline");
194 if ( $elHeader.children().is(".ui-option-header") ) {
195 $elContent.removeClass( "ui-title-content-" + tStyle + "-height" );
196 if ( $.tizen.optionheader.prototype.options.collapseOnInit == true ) {
197 $elContent.addClass( "ui-title-content-option-header-collapsed-1line-height" );
199 $elContent.addClass( "ui-title-content-option-header-expanded-1line-height" );
201 } else if ( $elHeader.find("input").attr("type") === "search" || $elHeader.find("input").attr("type") === "tizen-search" || $elHeader.find("input").jqmData("type") == "search" || $elHeader.find("input").jqmData("type") == "tizen-search" ) {
202 $elContent.removeClass( "ui-title-content-" + tStyle + "-height" ).addClass( "ui-title-content-search" );
205 headerBtnNum = $elHeader.children("a").length;
206 if ( headerBtnNum > 0 || $elHeader.children().find(".ui-radio").length != 0 ) {
207 if ( tStyle != "normal" ) {
208 gLength = $elFieldcontain.length ? $elFieldcontain.find( ".ui-radio" ).length : $elControlgroup.find( "a" ).length;
210 $elHeader.addClass( "ui-title-extended-height" );
212 $elFieldcontain.length ? $elFieldcontain.find( ".ui-controlgroup" ).addClass( "ui-title-extended-controlgroup" ).addClass( "ui-extended-controlgroup" ) : $elControlgroup.addClass( "ui-title-extended-button-controlgroup" ).addClass( "ui-extended-controlgroup" );
214 $elFieldcontain.length ? $elFieldcontain.addClass( "ui-title-extended-segment-style" ) : $elControlgroup.addClass( "ui-title-extended-segment-style" );
216 if ( gLength == 2 || gLength == 3 || gLength == 4 ) {
217 $elFieldcontain.length ? $elFieldcontain.addClass( "ui-title-extended-controlgroup-" + gLength + "btn" ) : $elControlgroup.addClass( "ui-title-extended-controlgroup-" + gLength + "btn" );
220 $elContent.addClass( "ui-title-content-" + tStyle + "-height" );
223 // divide content mode scrollview and non-scrollview
224 // recalculate content area when resize callback occur
225 if ( $.support.scrollview ) {
226 if ( $elHeader.css( "position" ) != "fixed" ) {
227 $elHeader.css( "position", "fixed" );
231 if ( $elHeader.css("position") != "fixed" ) {
232 $elHeader.css( "position", "relative" );
236 $elFooter = $( document ).find( ":jqmData(role='footer')" );
238 if ( $elFooter.find(".ui-navbar").is(".ui-controlbar-s") ) {
244 if ( $elFooter.children().find(".ui-radio").length != 0 ) {
245 $elFooterGroup = $elFooter.find( ":jqmData(role='fieldcontain')" );
246 gLength = $elFooterGroup.find( ".ui-radio" ).length;
249 if ( $elFooterGroup.find( "div" ).is( ".ui-controlgroup-label" ) ) {
250 $elFooterGroup.find( "div.ui-controlgroup-label" ).remove();
253 $elFooterGroup.find( ".ui-controlgroup" )
254 .addClass( "ui-extended-controlgroup" )
255 .addClass( "ui-footer-extended-controlgroup" )
256 .css( "display", "inline" );
258 /* Groupcontrol cannot initialize inline property at first page */
259 $elFooterGroup.addClass( "ui-footer-extended-controlgroup-" + gLength + "btn" );
262 footerButton = $elFooter.children( "a" );
263 footerButton.each( function ( i ) {
264 if ( footerButton.eq( i ).is(".ui-btn") && !footerButton.eq( i ).is(".ui-btn-back") ) {
266 .removeClass( "ui-btn-left" )
267 .addClass( "ui-btn-footer-right" );
271 if ( $elFooter.is(".ui-footer-fixed") ) {
272 $elFooter.css( "bottom", 0 );
277 /* Header position fix(remove transition) */
278 next_id = $( event.target ).attr( "id" );
280 $( "#" + next_id ).find( ":jqmData(role='header')" )
281 .removeClass( "fade in out" )
282 .appendTo( $.mobile.pageContainer );
285 _bindPageEvents: function () {
290 //page event bindings
291 // Fixed toolbars require page zoom to be disabled, otherwise usability issues crop up
292 // This method is meant to disable zoom while a fixed-positioned toolbar page is visible
293 $el.closest( ".ui-page" )
294 .bind( "pagebeforeshow", function ( event ) {
295 if ( o.disablePageZoom ) {
296 $.mobile.zoom.disable( true );
298 if ( !o.visibleOnPageShow ) {
301 /* IME concenpt change after alpha2.0 */
302 /* self._IMEShown = false;*/
303 self.setHeaderFooter( event );
305 .bind( "webkitAnimationStart animationstart updatelayout", function ( e, data ) {
306 if ( o.updatePagePadding ) {
307 self.updatePagePadding(data); // FIXME: unused function.
308 self.updatePageLayout(data);
312 .bind( "pageshow", function ( event ) {
313 self.updatePagePadding(); // FIXME: unused function.
314 self._updateHeaderArea();
315 if ( o.updatePagePadding ) {
316 $( window ).bind( "throttledresize." + self.widgetName, function () {
317 self.updatePagePadding(); // FIXME: unused function.
318 /* IME concenpt change after alpha2.0 */
319 /* self.layoutPageIME();*/
320 self.updatePageLayout();
321 self._updateHeaderArea();
325 /* Header position fix(remove transition) */
326 $( "body" ).children( ":jqmData(role='header')" )
327 .insertBefore( $(event.target).find(":jqmData(role='content')").eq( 0 ) );
331 .bind( "pagebeforehide", function ( e, ui ) {
332 if ( o.disablePageZoom ) {
333 $.mobile.zoom.enable( true );
335 if ( o.updatePagePadding ) {
336 $( window ).unbind( "throttledresize." + self.widgetName );
339 if ( o.trackPersistentToolbars ) {
340 var thisFooter = $( ".ui-footer-fixed:jqmData(id)", this ),
341 thisHeader = $( ".ui-header-fixed:jqmData(id)", this ),
342 nextFooter = thisFooter.length && ui.nextPage && $( ".ui-footer-fixed:jqmData(id='" + thisFooter.jqmData( "id" ) + "')", ui.nextPage ),
343 nextHeader = thisHeader.length && ui.nextPage && $( ".ui-header-fixed:jqmData(id='" + thisHeader.jqmData( "id" ) + "')", ui.nextPage );
345 nextFooter = nextFooter || $();
347 if ( nextFooter.length || nextHeader.length ) {
349 nextFooter.add( nextHeader ).appendTo( $.mobile.pageContainer );
351 ui.nextPage.one( "pageshow", function () {
352 nextFooter.add( nextHeader ).appendTo( this );
359 _bindContentControlEvents: function () {
364 $el.closest( ".ui-page" )
365 .bind( "pagebeforeshow", function ( event ) {
370 _updateHeaderArea : function() {
371 var $elPage = $( ".ui-page-active" ),
372 $elHeader = $elPage.find( ":jqmData(role='header')" ).length ? $elPage.find( ":jqmData(role='header')") : $elPage.siblings( ":jqmData(role='header')"),
373 headerBtnNum = $elHeader.children("a").length,
374 headerSrcNum = $elHeader.children("img").length;
376 $elHeader.find( "h1" ).css( "width", window.innerWidth - $elHeader.children( "a" ).width() * headerBtnNum - $elHeader.children( "a" ).width() / 4 - $elHeader.children( "img" ).width() * headerSrcNum * 4 );
377 /* add half width for default space between text and button, and img tag area is too narrow, so multiply three for img width*/
381 /* IME concenpt change after alpha2.0 */
382 /* _IMEShown : false,
383 _IMEindicatorHeight : window.outerHeight - window.innerHeight,
385 layoutPageIME: function () {
386 if ( $( document.activeElement ).is( "input" ) || $( document.activeElement ).is( "textarea" )
387 || $(".ui-page-active .ui-header .input-search-bar").length
388 || $(".ui-page-active .ui-content").find("input").length
389 || $(".ui-page-active .ui-content").find("textarea").length) {
391 if ( ( window.innerHeight + this._IMEindicatorHeight ) < window.outerHeight && window.innerWidth == window.outerWidth ) {
392 if ( this._IMEShown === false ) {
393 $( ".ui-page-active .ui-footer" ).hide();
394 this._IMEShown = true;
396 } else if ( ( window.innerHeight + this._IMEindicatorHeight ) >= window.outerHeight ) {
397 if ( this._IMEShown === true ) {
398 $( ".ui-page-active .ui-footer" ).show();
399 this._IMEShown = false;
403 if ( ( window.innerHeight + this._IMEindicatorHeight ) >= window.outerHeight ) {
404 if ( this._IMEShown === true ) {
405 $( ".ui-page-active .ui-footer" ).show();
406 this._IMEShown = false;
412 // This will set the content element's top or bottom padding equal to the toolbar's height
413 updatePagePadding: function (data) {
414 var $el = this.element,
415 header = $el.is( ".ui-header" );
417 // This behavior only applies to "fixed", not "fullscreen"
418 if ( this.options.fullscreen ) { return; }
420 // $el.closest( ".ui-page" ).css( "padding-" + ( header ? "top" : "bottom" ), $el.outerHeight() );
424 /* 1. Calculate toolbar width(only controlbar)
425 * 2. Calculate and update content height */
426 updatePageLayout: function ( receiveType ) {
429 $elPage = $( document ).find( ".ui-page-active" ),
430 $elHeader = $elPage.find( ":jqmData(role='header')" ),
431 $elContent = $elPage.find( ":jqmData(role='content')" ),
432 resultContentHeight = 0,
433 resultFooterHeight = 0,
434 resultHeaderHeight = 0;
436 if ( $elPage.length ) {
437 $elFooter = $( document ).find( ".ui-page-active" ).find( ":jqmData(role='footer')" );
439 $elFooter = $( document ).find( ":jqmData(role='footer')" ).eq( 0 );
441 $elFooterControlbar = $elFooter.find( ".ui-navbar" );
443 // calculate footer height
444 resultFooterHeight = ( $elFooter.css( "display" ) == "none" ) ? 0 : $elFooter.height();
445 resultHeaderHeight = ( $elHeader.css( "display" ) == "none" ) ? 0 : $elHeader.height();
447 if (resultFooterHeight != 0 ) {
448 $elFooter.css( "bottom", 0 );
450 if ( $elFooterControlbar.jqmData("style") == "toolbar" ) {
451 $elFooterControlbar.css( "width", window.innerWidth - $elFooterControlbar.siblings( ".ui-btn" ).width() - parseInt($elFooterControlbar.siblings(".ui-btn").css("right"), 10 ) * 2 );
454 resultContentHeight = window.innerHeight - resultFooterHeight - resultHeaderHeight;
456 if ( $.support.scrollview ) {
457 if ( $elHeader.css("position") != "fixed" ) {
458 $elHeader.css( "position", "fixed" );
461 $elContent.height( resultContentHeight -
462 parseFloat( $elContent.css("padding-top") ) -
463 parseFloat( $elContent.css("padding-bottom") ) );
465 if ( $elHeader.css("position") != "fixed" ) {
466 $elHeader.css( "position", "relative" );
468 $elContent.height( resultContentHeight );
472 // check this line need
473 // because another style title will be not supported to updatePageLayout
475 // in case title changed
477 $elContent.css( "top", resultHeaderHeight + "px" );
481 _useTransition: function ( notransition ) {
482 var $win = $( window ),
484 scroll = $win.scrollTop(),
485 elHeight = $el.height(),
486 pHeight = $el.closest( ".ui-page" ).height(),
487 viewportHeight = $.mobile.getScreenHeight(),
488 tbtype = $el.is( ":jqmData(role='header')" ) ? "header" : "footer";
490 return !notransition &&
491 ( this.options.transition && this.options.transition !== "none" &&
493 ( tbtype === "header" && !this.options.fullscreen && scroll > elHeight ) ||
494 ( tbtype === "footer" && !this.options.fullscreen && scroll + viewportHeight < pHeight - elHeight )
495 ) || this.options.fullscreen
499 show: function ( notransition ) {
500 /* var hideClass = "ui-fixed-hidden",
503 if ( this._useTransition( notransition ) ){
505 .removeClass( "out " + hideClass )
509 $el.removeClass( hideClass );
511 this._visible = true;*/
514 hide: function ( notransition ) {
515 /* var hideClass = "ui-fixed-hidden",
517 // if it's a slide transition, our new transitions need the reverse class as well to slide outward
518 outclass = "out" + ( this.options.transition === "slide" ? " reverse" : "" );
520 if ( this._useTransition( notransition ) ){
522 .addClass( outclass )
524 .animationComplete( function () {
525 $el.addClass( hideClass ).removeClass( outclass );
529 $el.addClass( hideClass ).removeClass( outclass );
531 this._visible = false;*/
534 toggle: function () {
535 this[ this._visible ? "hide" : "show" ]();
538 /* support external api for adding backbutton via javascript */
539 /* backButton: function ( target, status ){
540 this._addBackbutton( target, "external" );
543 destroy: function () {
544 this.element.removeClass( "ui-header-fixed ui-footer-fixed ui-header-fullscreen ui-footer-fullscreen in out fade slidedown slideup ui-fixed-hidden" );
545 this.element.closest( ".ui-page" ).removeClass( "ui-page-header-fixed ui-page-footer-fixed ui-page-header-fullscreen ui-page-footer-fullscreen" );
550 //auto self-init widgets
552 .bind( "pagecreate create", function ( e ) {
553 // DEPRECATED in 1.1: support for data-fullscreen=true|false on the page element.
554 // This line ensures it still works, but we recommend moving the attribute to the toolbars themselves.
555 if ( $( e.target ).jqmData( "fullscreen" ) ) {
556 $( $.mobile.pagelayout.prototype.options.initSelector, e.target ).not( ":jqmData(fullscreen)" ).jqmData( "fullscreen", true );
558 $.mobile.pagelayout.prototype.enhanceWithin( e.target );