@@ -52,39 +52,27 @@ $.widget( "ui.selectmenu", {
52
52
options . value = that . element [ 0 ] . value ;
53
53
}
54
54
55
+ // catch click event of the label
56
+ that . _bind ( {
57
+ 'click' : function ( event ) {
58
+ that . newelement . focus ( ) ;
59
+ event . preventDefault ( ) ;
60
+ }
61
+ } ) ;
62
+
55
63
that . _addNewelement ( ) ;
64
+ that . _bind ( that . newelement , that . _newelementEvents ) ;
65
+
56
66
that . _addList ( ) ;
57
-
58
- // built menu
59
67
that . refresh ( ) ;
60
68
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
- } ) ;
73
69
} ,
74
70
75
71
_addNewelement : function ( ) {
76
72
var that = this ,
77
73
options = this . options ,
78
74
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
+
88
76
// hide original select tag
89
77
that . element . hide ( ) ;
90
78
@@ -134,18 +122,6 @@ $.widget( "ui.selectmenu", {
134
122
var text = that . newelement . find ( "span.ui-button-text" ) ;
135
123
var setWidth = text . width ( ) + parseFloat ( text . css ( "padding-left" ) ) + parseFloat ( text . css ( "margin-left" ) ) ;
136
124
}
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
- } ) ;
149
125
150
126
// wrap list
151
127
that . listWrap = $ ( '<div />' )
@@ -177,6 +153,23 @@ $.widget( "ui.selectmenu", {
177
153
that . focus = item . index ;
178
154
}
179
155
} ) ;
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
+ } ) ;
180
173
} ,
181
174
182
175
refresh : function ( ) {
@@ -255,7 +248,6 @@ $.widget( "ui.selectmenu", {
255
248
close : function ( event , focus ) {
256
249
var that = this ,
257
250
options = this . options ;
258
-
259
251
if ( that . opened ) {
260
252
if ( options . dropdown ) {
261
253
that . newelement
@@ -332,7 +324,7 @@ $.widget( "ui.selectmenu", {
332
324
keydown : function ( event ) {
333
325
switch ( event . keyCode ) {
334
326
case $ . ui . keyCode . TAB :
335
- if ( this . opened ) this . close ( ) ;
327
+ if ( this . opened ) this . close ( event ) ;
336
328
break ;
337
329
case $ . ui . keyCode . ENTER :
338
330
if ( this . opened ) {
0 commit comments