Permalink
Browse files

[fixedToolbar] Move page handlers to the widget prototype level and a…

…ttach them using ._on()
  • Loading branch information...
gabrielschulhof committed Nov 18, 2012
1 parent 8bd31b5 commit e217cd9e435b3f6adaf8faf00c71a5f973ab5516
Showing with 58 additions and 50 deletions.
  1. +58 −50 js/widgets/fixedToolbar.js
View
@@ -107,62 +107,70 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
},
_bindPageEvents: function() {
var self = this,
o = self.options,
$el = self.element;
this._thisPage = this.element.closest( ".ui-page" );
//page event bindings
// Fixed toolbars require page zoom to be disabled, otherwise usability issues crop up
// This method is meant to disable zoom while a fixed-positioned toolbar page is visible
$el.closest( ".ui-page" )
.bind( "pagebeforeshow", function() {
if ( o.disablePageZoom ) {
$.mobile.zoom.disable( true );
}
if ( !o.visibleOnPageShow ) {
self.hide( true );
}
} )
.bind( "webkitAnimationStart animationstart updatelayout", function() {
var thisPage = this;
if ( o.updatePagePadding ) {
self.updatePagePadding( thisPage );
}
})
.bind( "pageshow", function() {
var thisPage = this;
self.updatePagePadding( thisPage );
if ( o.updatePagePadding ) {
$( window ).bind( "throttledresize." + self.widgetName, function() {
self.updatePagePadding( thisPage );
});
}
})
.bind( "pagebeforehide", function( e, ui ) {
if ( o.disablePageZoom ) {
$.mobile.zoom.enable( true );
}
if ( o.updatePagePadding ) {
$( window ).unbind( "throttledresize." + self.widgetName );
}
this._on( this._thisPage, {
"pagebeforeshow": "_handlePageBeforeShow",
"webkitAnimationStart animationstart updatelayout": "_handleAnimationStart",
"pageshow": "_handlePageShow",
"pagebeforehide": "_handlePageBeforeHide"
});
},
if ( o.trackPersistentToolbars ) {
var thisFooter = $( ".ui-footer-fixed:jqmData(id)", this ),
thisHeader = $( ".ui-header-fixed:jqmData(id)", this ),
nextFooter = thisFooter.length && ui.nextPage && $( ".ui-footer-fixed:jqmData(id='" + thisFooter.jqmData( "id" ) + "')", ui.nextPage ) || $(),
nextHeader = thisHeader.length && ui.nextPage && $( ".ui-header-fixed:jqmData(id='" + thisHeader.jqmData( "id" ) + "')", ui.nextPage ) || $();
_handlePageBeforeShow: function() {
var o = this.options;
if ( o.disablePageZoom ) {
$.mobile.zoom.disable( true );
}
if ( !o.visibleOnPageShow ) {
this.hide( true );
}
},
if ( nextFooter.length || nextHeader.length ) {
_handleAnimationStart: function() {
if ( this.options.updatePagePadding ) {
this.updatePagePadding( this._thisPage );
}
},
_handlePageShow: function() {
this.updatePagePadding( this._thisPage );
if ( this.options.updatePagePadding ) {
this._on( $( window ), { "throttledresize": "updatePagePadding" } );
}
},
nextFooter.add( nextHeader ).appendTo( $.mobile.pageContainer );
_handlePageBeforeHide: function( e, ui ) {
var o = this.options;
ui.nextPage.one( "pageshow", function() {
nextHeader.prependTo( this );
nextFooter.appendTo( this );
});
}
}
});
if ( o.disablePageZoom ) {
$.mobile.zoom.enable( true );
}
if ( o.updatePagePadding ) {
this._off( $( window ), "throttledresize" );
}
if ( o.trackPersistentToolbars ) {
var thisFooter = $( ".ui-footer-fixed:jqmData(id)", this._thisPage ),
thisHeader = $( ".ui-header-fixed:jqmData(id)", this._thisPage ),
nextFooter = thisFooter.length && ui.nextPage && $( ".ui-footer-fixed:jqmData(id='" + thisFooter.jqmData( "id" ) + "')", ui.nextPage ) || $(),
nextHeader = thisHeader.length && ui.nextPage && $( ".ui-header-fixed:jqmData(id='" + thisHeader.jqmData( "id" ) + "')", ui.nextPage ) || $();
if ( nextFooter.length || nextHeader.length ) {
nextFooter.add( nextHeader ).appendTo( $.mobile.pageContainer );
this._on( ui.nextPage, {
pageshow: function() {
nextHeader.prependTo( ui.nextPage );
nextFooter.appendTo( ui.nextPage );
this._off( ui.nextPage, "pageshow" );
}
});
}
}
},
_visible: true,
@@ -176,7 +184,7 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
// This behavior only applies to "fixed", not "fullscreen"
if ( this.options.fullscreen ) { return; }
tbPage = tbPage || $el.closest( ".ui-page" );
tbPage = tbPage || this._thisPage || $el.closest( ".ui-page" );
$( tbPage ).css( "padding-" + ( header ? "top" : "bottom" ), $el.outerHeight() + pos );
},

0 comments on commit e217cd9

Please sign in to comment.