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

Commit e741bc2

Browse files
committed
force close logic of custom select to run when close is clicked, centralize the binding for pagehide.remove
1 parent b837a49 commit e741bc2

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

js/jquery.mobile.dialog.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,36 @@ $.widget( "mobile.dialog", $.mobile.widget, {
1313
initSelector : ":jqmData(role='dialog')"
1414
},
1515
_create: function() {
16-
var $el = this.element,
17-
pageTheme = $el.attr( "class" ).match( /ui-body-[a-z]/ );
18-
16+
var self = this,
17+
$el = this.element,
18+
pageTheme = $el.attr( "class" ).match( /ui-body-[a-z]/ ),
19+
headerCloseButton = $( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText + "</a>" );
20+
1921
if( pageTheme.length ){
2022
$el.removeClass( pageTheme[ 0 ] );
21-
}
22-
23+
}
24+
2325
$el.addClass( "ui-body-" + this.options.theme );
24-
26+
2527
// Class the markup for dialog styling
2628
// Set aria role
2729
$el.attr( "role", "dialog" )
2830
.addClass( "ui-dialog" )
2931
.find( ":jqmData(role='header')" )
3032
.addClass( "ui-corner-top ui-overlay-shadow" )
31-
.prepend( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "rel='back' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText + "</a>" )
33+
.prepend( headerCloseButton )
3234
.end()
3335
.find( ":jqmData(role='content'),:jqmData(role='footer')" )
3436
.last()
3537
.addClass( "ui-corner-bottom ui-overlay-shadow" );
3638

39+
// this must be an anonymous function so that select menu dialogs can replace
40+
// the close method. This is a change from previously just defining data-rel=back
41+
// on the button and letting nav handle it
42+
headerCloseButton.bind( "vclick", function() {
43+
self.close();
44+
});
45+
3746
/* bind events
3847
- clicks and submits should use the closing transition that the dialog opened with
3948
unless a data-transition is specified on the link/form

js/jquery.mobile.forms.select.custom.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,9 @@
201201
}
202202
});
203203

204+
// track this dependency so that when the parent page
205+
// is removed on pagehide it will also remove the menupage
204206
self.thisPage.addDependent( this.menuPage );
205-
206-
self.menuPage.find(":jqmData(role='header') :jqmData(rel='back')").click(function() {
207-
self.close();
208-
return false;
209-
});
210207
},
211208

212209
_isRebuildRequired: function() {
@@ -270,11 +267,7 @@
270267
// rebind the page remove that was unbound in the open function
271268
// to allow for the parent page removal from actions other than the use
272269
// of a dialog sized custom select
273-
if( !self.thisPage.data("page").options.domCache ){
274-
self.thisPage.bind( "pagehide.remove", function() {
275-
$(this).removeWithDependents();
276-
});
277-
}
270+
$.mobile._bindPageRemove.call( self.thisPage );
278271

279272
// doesn't solve the possible issue with calling change page
280273
// where the objects don't define data urls which prevents dialog key
@@ -329,6 +322,11 @@
329322
});
330323
}
331324

325+
// set the dialog close function to that of the custom dialog
326+
self.menuPage.data( 'dialog' ).close = function() {
327+
self.close();
328+
};
329+
332330
self.menuPage.one( "pageshow", function() {
333331
// silentScroll() is called whenever a page is shown to restore
334332
// any previous scroll position the page may have had. We need to

js/jquery.mobile.listview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
272272
// on pagehide, remove any nested pages along with the parent page, as long as they aren't active
273273
// and aren't embedded
274274
if( hasSubPages &&
275-
parentPage.is( "jqmData(external-page='true')" ) &&
275+
parentPage.is( ":jqmData(external-page='true')" ) &&
276276
parentPage.data("page").options.domCache === false ) {
277277

278278
var newRemove = function( e, ui ){

js/jquery.mobile.navigation.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,20 @@
650650
return asParsedObject ? $.extend( {}, documentBase ) : documentBase.href;
651651
};
652652

653+
$.mobile._bindPageRemove = function() {
654+
var page = $(this);
655+
656+
// when dom caching is not enabled or the page is embedded bind to remove the page on hide
657+
if( !page.data("page").options.domCache
658+
&& page.is(":jqmData(external-page='true')") ) {
659+
660+
page.bind( 'pagehide.remove', function() {
661+
debugger;
662+
$( this ).removeWithDependents();
663+
});
664+
}
665+
};
666+
653667
// Load a page into the DOM.
654668
$.mobile.loadPage = function( url, options ) {
655669
// This function uses deferred notifications to let callers
@@ -849,15 +863,7 @@
849863
.appendTo( settings.pageContainer );
850864

851865
// wait for page creation to leverage options defined on widget
852-
page.one('pagecreate', function(){
853-
854-
// when dom caching is not enabled bind to remove the page on hide
855-
if( !page.data("page").options.domCache ){
856-
page.bind( "pagehide.remove", function(){
857-
$(this).removeWithDependents();
858-
});
859-
}
860-
});
866+
page.one( 'pagecreate', $.mobile._bindPageRemove );
861867

862868
enhancePage( page, settings.role );
863869

0 commit comments

Comments
 (0)