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

Commit 9be2bc9

Browse files
author
Gabriel Schulhof
committed
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.
1 parent b605521 commit 9be2bc9

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

js/widgets/dialog.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ $.widget( "mobile.dialog", $.mobile.widget, {
1717
corners: true,
1818
initSelector: ":jqmData(role='dialog')"
1919
},
20+
21+
// Override the theme set by the page plugin on pageshow
22+
_handlePageBeforeShow: function() {
23+
this._isCloseable = true;
24+
if ( this.options.overlayTheme ) {
25+
this.element
26+
.page( "removeContainerBackground" )
27+
.page( "setContainerBackground", this.options.overlayTheme );
28+
}
29+
},
30+
2031
_create: function() {
2132
var self = this,
2233
$el = this.element,
@@ -51,15 +62,10 @@ $.widget( "mobile.dialog", $.mobile.widget, {
5162
})
5263
.bind( "pagehide", function( e, ui ) {
5364
$( this ).find( "." + $.mobile.activeBtnClass ).not( ".ui-slider-bg" ).removeClass( $.mobile.activeBtnClass );
54-
})
55-
// Override the theme set by the page plugin on pageshow
56-
.bind( "pagebeforeshow", function() {
57-
self._isCloseable = true;
58-
if ( self.options.overlayTheme ) {
59-
self.element
60-
.page( "removeContainerBackground" )
61-
.page( "setContainerBackground", self.options.overlayTheme );
62-
}
65+
});
66+
67+
this._on( $el, {
68+
pagebeforeshow: "_handlePageBeforeShow"
6369
});
6470

6571
$.extend( this, {

0 commit comments

Comments
 (0)