@@ -105,8 +105,8 @@ $.widget( "ui.selectmenu", {
105
105
if ( this . options . dropdown ) {
106
106
var setWidth = this . button . outerWidth ( ) ;
107
107
} else {
108
- var text = this . button . find ( "span.ui-button-text" ) ;
109
- var setWidth = text . width ( ) + parseFloat ( text . css ( "padding-left" ) ) || 0 + parseFloat ( text . css ( "margin-left" ) || 0 ) ;
108
+ var text = this . button . find ( "span.ui-button-text" ) ,
109
+ setWidth = text . width ( ) + parseFloat ( text . css ( "padding-left" ) ) || 0 + parseFloat ( text . css ( "margin-left" ) || 0 ) ;
110
110
}
111
111
112
112
// wrap menu
@@ -119,8 +119,7 @@ $.widget( "ui.selectmenu", {
119
119
// init menu widget
120
120
this . menu . menu ( {
121
121
select : function ( event , ui ) {
122
- var flag = false ,
123
- item = ui . item . data ( "item.selectmenu" ) ,
122
+ var item = ui . item . data ( "item.selectmenu" ) ,
124
123
oldIndex = that . element [ 0 ] . selectedIndex ;
125
124
126
125
that . _setIndex ( item . index ) ;
@@ -147,6 +146,9 @@ $.widget( "ui.selectmenu", {
147
146
} )
148
147
// change ARIA role
149
148
. attr ( 'role' , 'menubox' ) ;
149
+
150
+ // change menu styles?
151
+ this . _setOption ( "dropdown" , this . options . dropdown ) ;
150
152
151
153
// document click closes menu
152
154
this . _bind ( document , {
@@ -172,9 +174,6 @@ $.widget( "ui.selectmenu", {
172
174
this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) . find ( 'a' ) . attr ( 'role' , 'option' ) ;
173
175
this . menu . attr ( "aria-activedescendant" , this . menu . find ( "li.ui-menu-item a" ) . eq ( this . element [ 0 ] . selectedIndex ) . attr ( "id" ) ) ;
174
176
175
- // change styles?
176
- this . _setOption ( "dropdown" , this . options . dropdown ) ;
177
-
178
177
// transfer disabled state
179
178
if ( this . element . attr ( 'disabled' ) ) {
180
179
this . disable ( ) ;
@@ -184,14 +183,10 @@ $.widget( "ui.selectmenu", {
184
183
} ,
185
184
186
185
open : function ( event ) {
187
- var currentItem = this . _getSelectedItem ( ) ;
188
-
189
186
if ( ! this . options . disabled ) {
190
- if ( this . options . dropdown ) {
191
- this . button
192
- . addClass ( 'ui-corner-top' )
193
- . removeClass ( 'ui-corner-all' ) ;
194
- }
187
+ var currentItem = this . _getSelectedItem ( ) ;
188
+
189
+ this . _toggleButtonStyle ( ) ;
195
190
196
191
this . menuWrap . addClass ( 'ui-selectmenu-open' ) ;
197
192
this . menu . attr ( "aria-hidden" , false ) ;
@@ -203,12 +198,11 @@ $.widget( "ui.selectmenu", {
203
198
} , 1 ) ;
204
199
205
200
if ( ! this . options . dropdown ) {
206
- // calculate offset
207
- var _offset = ( this . menu . offset ( ) . top - currentItem . offset ( ) . top + ( this . button . outerHeight ( ) - currentItem . outerHeight ( ) ) / 2 ) ;
208
201
$ . extend ( this . options . position , {
209
202
my : "left top" ,
210
203
at : "left top" ,
211
- offset : "0 " + _offset
204
+ // calculate offset
205
+ offset : "0 " + ( this . menu . offset ( ) . top - currentItem . offset ( ) . top + ( this . button . outerHeight ( ) - currentItem . outerHeight ( ) ) / 2 )
212
206
} ) ;
213
207
}
214
208
@@ -225,11 +219,7 @@ $.widget( "ui.selectmenu", {
225
219
226
220
close : function ( event , focus ) {
227
221
if ( this . isOpen ) {
228
- if ( this . options . dropdown ) {
229
- this . button
230
- . addClass ( 'ui-corner-all' )
231
- . removeClass ( 'ui-corner-top' ) ;
232
- }
222
+ this . _toggleButtonStyle ( ) ;
233
223
234
224
this . menuWrap . removeClass ( 'ui-selectmenu-open' ) ;
235
225
this . menu . attr ( "aria-hidden" , true ) ;
@@ -309,8 +299,8 @@ $.widget( "ui.selectmenu", {
309
299
} ,
310
300
311
301
_buttonEvents : {
312
- // init Menu on first focus
313
302
focus : function ( event ) {
303
+ // init Menu on first focus
314
304
this . refresh ( ) ;
315
305
this . button . unbind ( "focus." + this . widgetName )
316
306
} ,
@@ -399,6 +389,12 @@ $.widget( "ui.selectmenu", {
399
389
}
400
390
}
401
391
} ,
392
+
393
+ _toggleButtonStyle : function ( ) {
394
+ if ( this . options . dropdown ) {
395
+ this . button . toggleClass ( 'ui-corner-top' , ! this . isOpen ) . toggleClass ( 'ui-corner-all' , this . isOpen ) ;
396
+ }
397
+ } ,
402
398
403
399
_readOptions : function ( ) {
404
400
var data = [ ] ;
0 commit comments