Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Page: Attach handlers using ._on(). Helps fix #2215
Browse files Browse the repository at this point in the history
When a page widget is destroyed on an element, the pagebeforehide and pagebeforeshow handlers must be removed, otherwise, if another page widget is instantiated on the same element later on, the handlers from the previous instance will be left around and so the new instance will have the two events handled twice.
  • Loading branch information
Gabriel Schulhof committed Nov 23, 2012
1 parent 407b948 commit b605521
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions js/widgets/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,29 @@ $.widget( "mobile.page", $.mobile.widget, {
},

_create: function() {

var self = this;

// if false is returned by the callbacks do not create the page
if ( self._trigger( "beforecreate" ) === false ) {
if ( this._trigger( "beforecreate" ) === false ) {
return false;
}

self.element
this.element
.attr( "tabindex", "0" )
.addClass( "ui-page ui-body-" + self.options.theme )
.bind( "pagebeforehide", function() {
self.removeContainerBackground();
} )
.bind( "pagebeforeshow", function() {
self.setContainerBackground();
} );
.addClass( "ui-page ui-body-" + this.options.theme );

this._on( this.element, {
pagebeforehide: "removeContainerBackground",
pagebeforeshow: "_handlePageBeforeShow"
});
},


_handlePageBeforeShow: function( e ) {
this.setContainerBackground();
},

removeContainerBackground: function() {
$.mobile.pageContainer.removeClass( "ui-overlay-" + $.mobile.getInheritedTheme( this.element.parent() ) );
},

// set the page container background to the page theme
setContainerBackground: function( theme ) {
if ( this.options.theme ) {
Expand Down

0 comments on commit b605521

Please sign in to comment.