Skip to content

Commit f4454ce

Browse files
committed
Selectmenu: fixed click scrollbar issue (follow up), improved document event handling
1 parent ac54556 commit f4454ce

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,27 @@ $.widget( "ui.selectmenu", {
5252
options.value = that.element[0].value;
5353
}
5454

55+
// catch click event of the label
56+
that._bind({
57+
'click': function( event ) {
58+
that.newelement.focus();
59+
event.preventDefault();
60+
}
61+
});
62+
5563
that._addNewelement();
64+
that._bind( that.newelement, that._newelementEvents );
65+
5666
that._addList();
57-
58-
// built menu
5967
that.refresh();
6068

61-
that._bind( that.newelement, that._newelementEvents );
62-
63-
// document click closes menu
64-
that._bind( document, {
65-
'mousedown': function( event ) {
66-
if ( that.opened && !that.hover) {
67-
window.setTimeout( function() {
68-
that.close( event );
69-
}, 200 );
70-
}
71-
}
72-
});
7369
},
7470

7571
_addNewelement: function() {
7672
var that = this,
7773
options = this.options,
7874
tabindex = this.element.attr( 'tabindex' );
79-
80-
// catch click event of the label
81-
that._bind({
82-
'click': function( event ) {
83-
that.newelement.focus();
84-
event.preventDefault();
85-
}
86-
});
87-
75+
8876
// hide original select tag
8977
that.element.hide();
9078

@@ -134,18 +122,6 @@ $.widget( "ui.selectmenu", {
134122
var text = that.newelement.find( "span.ui-button-text");
135123
var setWidth = text.width() + parseFloat( text.css( "padding-left" ) ) + parseFloat( text.css( "margin-left" ) );
136124
}
137-
138-
that._bind( that.list, {
139-
'click': function( event ) {
140-
event.preventDefault();
141-
},
142-
mouseenter: function() {
143-
that.hover = true;
144-
},
145-
mouseleave: function() {
146-
that.hover = false;
147-
}
148-
});
149125

150126
// wrap list
151127
that.listWrap = $( '<div />' )
@@ -177,6 +153,23 @@ $.widget( "ui.selectmenu", {
177153
that.focus = item.index;
178154
}
179155
});
156+
157+
that._bind( that.list, {
158+
'click': function( event ) {
159+
event.preventDefault();
160+
}
161+
});
162+
163+
// document click closes menu
164+
that._bind( document, {
165+
'mousedown': function( event ) {
166+
if ( that.opened && !$( event.target ).is( that.list ) ) {
167+
window.setTimeout( function() {
168+
that.close( event );
169+
}, 200 );
170+
}
171+
}
172+
});
180173
},
181174

182175
refresh: function() {
@@ -255,7 +248,6 @@ $.widget( "ui.selectmenu", {
255248
close: function( event, focus ) {
256249
var that = this,
257250
options = this.options;
258-
259251
if ( that.opened ) {
260252
if ( options.dropdown ) {
261253
that.newelement
@@ -332,7 +324,7 @@ $.widget( "ui.selectmenu", {
332324
keydown: function( event ) {
333325
switch (event.keyCode) {
334326
case $.ui.keyCode.TAB:
335-
if ( this.opened ) this.close();
327+
if ( this.opened ) this.close( event );
336328
break;
337329
case $.ui.keyCode.ENTER:
338330
if ( this.opened ) {

0 commit comments

Comments
 (0)