Skip to content

Commit e7691a7

Browse files
author
Gabriel Schulhof
committed
Custom select: Moving focusMenuItem() into the widget prototype and calling it _focusMenuItem().
1 parent a30522e commit e7691a7

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

js/widgets/forms/select.custom.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
344344
this.button.click();
345345
},
346346

347+
_focusMenuItem: function() {
348+
var selector = this.list.find( "a." + $.mobile.activeBtnClass );
349+
if ( selector.length === 0 ) {
350+
selector = this.list.find( "li:not(" + unfocusableItemSelector + ") a.ui-btn" );
351+
}
352+
selector.first().focus();
353+
},
354+
347355
_decideFormat: function() {
348356
var self = this,
349357
$window = $.mobile.window,
@@ -353,14 +361,6 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
353361
btnOffset = self.button.offset().top,
354362
screenHeight = $window.height();
355363

356-
function focusMenuItem() {
357-
var selector = self.list.find( "a." + $.mobile.activeBtnClass );
358-
if ( selector.length === 0 ) {
359-
selector = self.list.find( "li:not(" + unfocusableItemSelector + ") a.ui-btn" );
360-
}
361-
selector.first().focus();
362-
}
363-
364364
if ( menuHeight > screenHeight - 80 || !$.support.scrollTop ) {
365365

366366
self.menuPage.appendTo( $.mobile.pageContainer ).page();
@@ -379,21 +379,18 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
379379
});
380380
}
381381

382-
self.menuPage
383-
.one( "pageshow", function() {
384-
focusMenuItem();
385-
})
386-
.one( "pagehide", function() {
387-
self.close();
388-
});
382+
self.menuPage.one( {
383+
pageshow: $.proxy( this, "_focusMenuItem" ),
384+
pagehide: $.proxy( this, "close" )
385+
});
389386

390387
self.menuType = "page";
391388
self.menuPageContent.append( self.list );
392389
self.menuPage.find( "div .ui-title" ).text( self.label.text() );
393390
} else {
394391
self.menuType = "overlay";
395392

396-
self.listbox.one( "popupafteropen", focusMenuItem );
393+
self.listbox.one( { popupafteropen: $.proxy( this, "_focusMenuItem" ) } );
397394
}
398395
},
399396

0 commit comments

Comments
 (0)