From b6055211678cd2138ad91c6a328d3c233948de9e Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Fri, 23 Nov 2012 23:33:17 +0200 Subject: [PATCH] Page: Attach handlers using ._on(). Helps fix #2215 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. --- js/widgets/page.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/js/widgets/page.js b/js/widgets/page.js index 256fbb2e40b..846c6ee79e2 100644 --- a/js/widgets/page.js +++ b/js/widgets/page.js @@ -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 ) {