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

Commit b17e504

Browse files
author
Gabriel Schulhof
committed
Custom select: Moving binding that opens the select into the widget prototype and calling it _handleButtonVclickKeydown().
1 parent a0c6e1a commit b17e504

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

js/widgets/forms/select.custom.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
5353
this.button.focus();
5454
},
5555

56+
_handleButtonVclickKeydown: function( event ) {
57+
if ( this.options.disabled || this.isOpen ) {
58+
return;
59+
}
60+
61+
if (event.type === "vclick" ||
62+
event.keyCode && (event.keyCode === $.mobile.keyCode.ENTER || event.keyCode === $.mobile.keyCode.SPACE)) {
63+
64+
this._decideFormat();
65+
if ( this.menuType === "overlay" ) {
66+
this.button.attr( "href", "#" + this.popupId ).attr( "data-" + ( $.mobile.ns || "" ) + "rel", "popup" );
67+
} else {
68+
this.button.attr( "href", "#" + this.dialogId ).attr( "data-" + ( $.mobile.ns || "" ) + "rel", "dialog" );
69+
}
70+
this.isOpen = true;
71+
// Do not prevent default, so the navigation may have a chance to actually open the chosen format
72+
}
73+
},
74+
5675
build: function() {
5776
var selectId, prefix, popupId, dialogId, label, thisPage, isMultiple, menuId, themeAttr, overlayThemeAttr,
5877
dividerThemeAttr, menuPage, listbox, list, header, headerTitle, menuPageContent, menuPageClose, headerClose, self,
@@ -128,23 +147,9 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
128147
this._on( this.select, { focus : "_handleSelectFocus" } );
129148

130149
// Button events
131-
this.button.bind( "vclick keydown" , function( event ) {
132-
if ( self.options.disabled || self.isOpen ) {
133-
return;
134-
}
135-
136-
if (event.type === "vclick" ||
137-
event.keyCode && (event.keyCode === $.mobile.keyCode.ENTER || event.keyCode === $.mobile.keyCode.SPACE)) {
138-
139-
self._decideFormat();
140-
if ( self.menuType === "overlay" ) {
141-
self.button.attr( "href", "#" + self.popupId ).attr( "data-" + ( $.mobile.ns || "" ) + "rel", "popup" );
142-
} else {
143-
self.button.attr( "href", "#" + self.dialogId ).attr( "data-" + ( $.mobile.ns || "" ) + "rel", "dialog" );
144-
}
145-
self.isOpen = true;
146-
// Do not prevent default, so the navigation may have a chance to actually open the chosen format
147-
}
150+
this._on( this.button, {
151+
vclick : "_handleButtonVclickKeydown",
152+
keydown : "_handleButtonVclickKeydown"
148153
});
149154

150155
// Events for list items

0 commit comments

Comments
 (0)