Skip to content

Commit 04b2f73

Browse files
author
Gabriel Schulhof
committed
Custom select: Moving item-to-item focus transfer binding into the widget prototype and calling it _handleListFocus().
1 parent b17e504 commit 04b2f73

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

js/widgets/forms/select.custom.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
7272
}
7373
},
7474

75+
_handleListFocus: function( e ) {
76+
var params = ( e.type === "focusin" ) ?
77+
{ tabindex: "0", event: "vmouseover" }:
78+
{ tabindex: "-1", event: "vmouseout" };
79+
80+
$( e.target )
81+
.attr( "tabindex", params.tabindex )
82+
.trigger( params.event );
83+
},
84+
7585
build: function() {
7686
var selectId, prefix, popupId, dialogId, label, thisPage, isMultiple, menuId, themeAttr, overlayThemeAttr,
7787
dividerThemeAttr, menuPage, listbox, list, header, headerTitle, menuPageContent, menuPageClose, headerClose, self,
@@ -153,18 +163,12 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
153163
});
154164

155165
// Events for list items
156-
this.list.attr( "role", "listbox" )
157-
.bind( "focusin", function( e ) {
158-
$( e.target )
159-
.attr( "tabindex", "0" )
160-
.trigger( "vmouseover" );
161-
162-
})
163-
.bind( "focusout", function( e ) {
164-
$( e.target )
165-
.attr( "tabindex", "-1" )
166-
.trigger( "vmouseout" );
167-
})
166+
this.list.attr( "role", "listbox" );
167+
this._on( this.list, {
168+
focusin : "_handleListFocus",
169+
focusout : "_handleListFocus"
170+
});
171+
this.list
168172
.delegate( "li:not(.ui-disabled, .ui-li-divider)", "click", function( event ) {
169173

170174
// index of option tag to be selected

0 commit comments

Comments
 (0)