Skip to content

Commit ada4673

Browse files
author
scottjehl
committed
abstracted out some of the page hide behavior to fix issues with the close button not returning focus to the button after closing. Also fixes an issue where a full page custom menu would open as a misplaced small custom menu the second time it opens (if the menu was closed via the custom close button). Fixes jquery-archive#1618. Fixes jquery-archive#1692. Fixes jquery-archive#1750.
1 parent 2de817d commit ada4673

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

js/jquery.mobile.forms.select.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
305305
break;
306306
}
307307
});
308+
309+
// button refocus ensures proper height calculation
310+
// by removing the inline style and ensuring page inclusion
311+
self.menuPage.bind( "pagehide", function(){
312+
self.list.appendTo( self.listbox );
313+
self._focusButton();
314+
});
308315

309316
// Events on "screen" overlay
310317
screen.bind( "vclick", function( event ) {
@@ -551,6 +558,13 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
551558
self.isOpen = true;
552559
}
553560
},
561+
562+
_focusButton : function(){
563+
var self = this;
564+
setTimeout(function() {
565+
self.button.focus();
566+
}, 40);
567+
},
554568

555569
close: function() {
556570
if ( this.options.disabled || !this.isOpen || this.options.nativeMenu ) {
@@ -559,19 +573,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
559573

560574
var self = this;
561575

562-
function focusButton() {
563-
setTimeout(function() {
564-
self.button.focus();
565-
}, 40);
566-
567-
self.listbox.removeAttr( "style" ).append( self.list );
568-
}
569-
570576
if ( self.menuType == "page" ) {
571-
// button refocus ensures proper height calculation
572-
// by removing the inline style and ensuring page inclusion
573-
self.menuPage.one( "pagehide", focusButton);
574-
575577
// doesn't solve the possible issue with calling change page
576578
// where the objects don't define data urls which prevents dialog key
577579
// stripping - changePage has incoming refactor
@@ -580,7 +582,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
580582
else{
581583
self.screen.addClass( "ui-screen-hidden" );
582584
self.listbox.addClass( "ui-selectmenu-hidden" ).removeAttr( "style" ).removeClass( "in" );
583-
focusButton();
585+
self._focusButton();
584586
}
585587

586588
// allow the dialog to be closed again

0 commit comments

Comments
 (0)