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

Commit b605521

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

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

js/widgets/page.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,29 @@ $.widget( "mobile.page", $.mobile.widget, {
1515
},
1616

1717
_create: function() {
18-
19-
var self = this;
20-
2118
// if false is returned by the callbacks do not create the page
22-
if ( self._trigger( "beforecreate" ) === false ) {
19+
if ( this._trigger( "beforecreate" ) === false ) {
2320
return false;
2421
}
2522

26-
self.element
23+
this.element
2724
.attr( "tabindex", "0" )
28-
.addClass( "ui-page ui-body-" + self.options.theme )
29-
.bind( "pagebeforehide", function() {
30-
self.removeContainerBackground();
31-
} )
32-
.bind( "pagebeforeshow", function() {
33-
self.setContainerBackground();
34-
} );
25+
.addClass( "ui-page ui-body-" + this.options.theme );
3526

27+
this._on( this.element, {
28+
pagebeforehide: "removeContainerBackground",
29+
pagebeforeshow: "_handlePageBeforeShow"
30+
});
3631
},
37-
32+
33+
_handlePageBeforeShow: function( e ) {
34+
this.setContainerBackground();
35+
},
36+
3837
removeContainerBackground: function() {
3938
$.mobile.pageContainer.removeClass( "ui-overlay-" + $.mobile.getInheritedTheme( this.element.parent() ) );
4039
},
41-
40+
4241
// set the page container background to the page theme
4342
setContainerBackground: function( theme ) {
4443
if ( this.options.theme ) {

0 commit comments

Comments
 (0)