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

Commit

Permalink
Dialog: Attach pagebeforeshow handler using ._on(). Fixes #2215.
Browse files Browse the repository at this point in the history
When a dialog widget is destroyed on an element, the pagebeforeshow handler must be removed, otherwise, if another dialog widget is instantiated on the same element later on, the handler from the previous instance will be left around and so the new instance will have the event handled twice.
  • Loading branch information
Gabriel Schulhof committed Nov 23, 2012
1 parent b605521 commit 9be2bc9
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions js/widgets/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ $.widget( "mobile.dialog", $.mobile.widget, {
corners: true,
initSelector: ":jqmData(role='dialog')"
},

// Override the theme set by the page plugin on pageshow
_handlePageBeforeShow: function() {
this._isCloseable = true;
if ( this.options.overlayTheme ) {
this.element
.page( "removeContainerBackground" )
.page( "setContainerBackground", this.options.overlayTheme );
}
},

_create: function() {
var self = this,
$el = this.element,
Expand Down Expand Up @@ -51,15 +62,10 @@ $.widget( "mobile.dialog", $.mobile.widget, {
})
.bind( "pagehide", function( e, ui ) {
$( this ).find( "." + $.mobile.activeBtnClass ).not( ".ui-slider-bg" ).removeClass( $.mobile.activeBtnClass );
})
// Override the theme set by the page plugin on pageshow
.bind( "pagebeforeshow", function() {
self._isCloseable = true;
if ( self.options.overlayTheme ) {
self.element
.page( "removeContainerBackground" )
.page( "setContainerBackground", self.options.overlayTheme );
}
});

this._on( $el, {
pagebeforeshow: "_handlePageBeforeShow"
});

$.extend( this, {
Expand Down

0 comments on commit 9be2bc9

Please sign in to comment.