Permalink
Browse files

Dialog: Attach pagebeforeshow handler using ._on(). Fixes #2215.

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...
1 parent b605521 commit 9be2bc9e71561891cb8b563fe2d88a50f8139cf9 @gabrielschulhof gabrielschulhof committed Nov 23, 2012
Showing with 15 additions and 9 deletions.
  1. +15 −9 js/widgets/dialog.js
View
@@ -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,
@@ -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, {

0 comments on commit 9be2bc9

Please sign in to comment.