@@ -72,9 +72,7 @@ $.widget( "ui.selectmenu", {
72
72
href : '#' + this . ids . id ,
73
73
tabindex : ( tabindex ? tabindex : this . options . disabled ? - 1 : 0 ) ,
74
74
id : this . ids . button ,
75
- css : {
76
- width : this . element . outerWidth ( )
77
- } ,
75
+ width : this . element . outerWidth ( ) ,
78
76
'aria-expanded' : false ,
79
77
'aria-autocomplete' : 'list' ,
80
78
'aria-owns' : this . ids . menu ,
@@ -89,8 +87,9 @@ $.widget( "ui.selectmenu", {
89
87
. attr ( 'role' , 'combobox' ) ;
90
88
91
89
// wrap and insert new button
92
- this . buttonWrap = $ ( '<span />' )
93
- . addClass ( 'ui-selectmenu-button' )
90
+ this . buttonWrap = $ ( '<span />' , {
91
+ 'class' : 'ui-selectmenu-button'
92
+ } )
94
93
. append ( this . button )
95
94
. insertAfter ( this . element ) ;
96
95
} ,
@@ -114,9 +113,10 @@ $.widget( "ui.selectmenu", {
114
113
}
115
114
116
115
// wrap menu
117
- this . menuWrap = $ ( '<div />' )
118
- . addClass ( 'ui-selectmenu-menu' )
119
- . width ( setWidth )
116
+ this . menuWrap = $ ( '<div />' , {
117
+ 'class' : 'ui-selectmenu-menu' ,
118
+ width : setWidth
119
+ } )
120
120
. append ( this . menu )
121
121
. appendTo ( this . options . appendTo ) ;
122
122
@@ -146,7 +146,6 @@ $.widget( "ui.selectmenu", {
146
146
if ( that . focus !== undefined && item . index != that . focus ) {
147
147
that . _trigger ( "focus" , event , { item : item } ) ;
148
148
}
149
-
150
149
that . focus = item . index ;
151
150
}
152
151
} )
@@ -158,7 +157,7 @@ $.widget( "ui.selectmenu", {
158
157
159
158
// document click closes menu
160
159
this . _bind ( document , {
161
- ' click' : function ( event ) {
160
+ click : function ( event ) {
162
161
if ( this . isOpen && ! $ ( event . target ) . closest ( "#" + this . ids . button ) . length ) {
163
162
this . close ( event ) ;
164
163
}
@@ -173,9 +172,10 @@ $.widget( "ui.selectmenu", {
173
172
this . _renderMenu ( this . menu , this . items ) ;
174
173
175
174
this . menu . menu ( "refresh" ) ;
175
+ this . menuItems = this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) ;
176
176
177
177
// adjust ARIA
178
- this . _getItems ( ) . find ( 'a' ) . attr ( 'role' , 'option' ) ;
178
+ this . menuItems . find ( 'a' ) . attr ( 'role' , 'option' ) ;
179
179
this . _setSelected ( ) ;
180
180
181
181
// set and transfer disabled state
@@ -280,7 +280,7 @@ $.widget( "ui.selectmenu", {
280
280
_move : function ( direction , event ) {
281
281
if ( direction == "first" || direction == "last" ) {
282
282
// set focus manually for first or last item
283
- this . menu . menu ( "focus" , event , this . _getItems ( ) [ direction ] ( ) ) ;
283
+ this . menu . menu ( "focus" , event , this . menuItems [ direction ] ( ) ) ;
284
284
} else {
285
285
// if menu is closed we need to focus the element first to indicate correct element
286
286
if ( ! this . isOpen ) {
@@ -297,11 +297,7 @@ $.widget( "ui.selectmenu", {
297
297
} ,
298
298
299
299
_getSelectedItem : function ( ) {
300
- return this . _getItems ( ) . eq ( this . element [ 0 ] . selectedIndex ) ;
301
- } ,
302
-
303
- _getItems : function ( ) {
304
- return this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) ;
300
+ return this . menuItems . eq ( this . element [ 0 ] . selectedIndex ) ;
305
301
} ,
306
302
307
303
_toggle : function ( event ) {
@@ -355,7 +351,6 @@ $.widget( "ui.selectmenu", {
355
351
break ;
356
352
case $ . ui . keyCode . HOME :
357
353
case $ . ui . keyCode . PAGE_UP :
358
- console . log ( "test" ) ;
359
354
this . _move ( "first" , event ) ;
360
355
break ;
361
356
case $ . ui . keyCode . END :
@@ -373,13 +368,14 @@ $.widget( "ui.selectmenu", {
373
368
} ,
374
369
375
370
_setSelected : function ( ) {
376
- var item = this . _getSelectedItem ( ) . find ( "a" ) ;
371
+ var item = this . _getSelectedItem ( ) ,
372
+ link = item . find ( "a" ) ;
377
373
// update button text
378
374
this . button . button ( "option" , "label" , item . text ( ) ) ;
379
375
// change ARIA attr
380
- this . button . add ( this . menu ) . attr ( "aria-activedescendant" , item . attr ( "id" ) ) ;
381
- this . _getItems ( ) . find ( "a" ) . attr ( "aria-selected" , false ) ;
382
- item . attr ( "aria-selected" , true ) ;
376
+ this . button . add ( this . menu ) . attr ( "aria-activedescendant" , link . attr ( "id" ) ) ;
377
+ this . menuItems . find ( "a" ) . attr ( "aria-selected" , false ) ;
378
+ link . attr ( "aria-selected" , true ) ;
383
379
} ,
384
380
385
381
_setOption : function ( key , value ) {
@@ -412,11 +408,7 @@ $.widget( "ui.selectmenu", {
412
408
} ,
413
409
414
410
_getCreateOptions : function ( ) {
415
- if ( this . element . attr ( 'disabled' ) ) {
416
- this . options . disabled = true ;
417
- } else {
418
- this . options . disabled = false ;
419
- }
411
+ this . options . disabled = ( this . element . attr ( 'disabled' ) ) ? true : false ;
420
412
} ,
421
413
422
414
_readOptions : function ( ) {
0 commit comments