Skip to content

Commit 10b905a

Browse files
author
scottjehl
committed
Before a page is shown, add its theme to the page container. This ensures that a page will transition through the color of the page that is going to be shown. Before a page is hidden, remove its theme class from the container. Pagehide is triggered before pageshow, so the newly showing page will be set on the container before the transition, despite the removal from the outgoing page's pagehide event. Lastly, the dialog plugin overrides the page container theme when a dialog is about to be shown. Fixes jquery-archive#3735
1 parent f3b9b0e commit 10b905a

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

js/jquery.mobile.dialog.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,13 @@ $.widget( "mobile.dialog", $.mobile.widget, {
6666
})
6767
.bind( "pagehide", function( e, ui ) {
6868
$( this ).find( "." + $.mobile.activeBtnClass ).removeClass( $.mobile.activeBtnClass );
69-
70-
// if there's an overlay theme, we're going to remove it from the page container.
71-
// First though, check that the incoming page isn't a dialog with the same theme. If so, don't remove.
72-
if( self.options.overlayTheme ){
73-
if( !ui.nextPage || !ui.nextPage.is( ".ui-dialog.ui-overlay-" + self.options.overlayTheme ) ){
74-
$.mobile.pageContainer.removeClass( "ui-overlay-" + self.options.overlayTheme );
75-
}
76-
}
7769
})
70+
// Override the theme set by the page plugin on pageshow
7871
.bind( "pagebeforeshow", function(){
7972
if( self.options.overlayTheme ){
80-
$.mobile.pageContainer.addClass( "ui-overlay-" + self.options.overlayTheme );
73+
self.element
74+
.page( "removeContainerBackground" )
75+
.page( "setContainerBackground", self.options.overlayTheme );
8176
}
8277
});
8378
},

js/jquery.mobile.page.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,35 @@ $.widget( "mobile.page", $.mobile.widget, {
1414
},
1515

1616
_create: function() {
17-
17+
18+
var self = this;
19+
1820
// if false is returned by the callbacks do not create the page
19-
if( this._trigger( "beforecreate" ) === false ){
21+
if( self._trigger( "beforecreate" ) === false ){
2022
return false;
2123
}
2224

23-
this.element
25+
self.element
2426
.attr( "tabindex", "0" )
25-
.addClass( "ui-page ui-body-" + this.options.theme );
27+
.addClass( "ui-page ui-body-" + self.options.theme )
28+
.bind( "pagebeforehide", function(){
29+
self.removeContainerBackground();
30+
} )
31+
.bind( "pagebeforeshow", function(){
32+
self.setContainerBackground();
33+
} );
34+
35+
},
36+
37+
removeContainerBackground: function(){
38+
$.mobile.pageContainer.removeClass( "ui-overlay-" + $.mobile.getInheritedTheme( this.element ) );
39+
},
40+
41+
// set the page container background to the page theme
42+
setContainerBackground: function( theme ){
43+
if( this.options.theme ){
44+
$.mobile.pageContainer.addClass( "ui-overlay-" + ( theme || this.options.theme ) );
45+
}
2646
},
2747

2848
keepNativeSelector: function() {

0 commit comments

Comments
 (0)