Skip to content

Commit 8f9632a

Browse files
committed
Selectmenu: minor improvements
1 parent 4dbbd05 commit 8f9632a

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ $.widget( "ui.selectmenu", {
7272
href: '#' + this.ids.id,
7373
tabindex: ( tabindex ? tabindex : this.options.disabled ? -1 : 0 ),
7474
id: this.ids.button,
75-
css: {
76-
width: this.element.outerWidth()
77-
},
75+
width: this.element.outerWidth(),
7876
'aria-expanded': false,
7977
'aria-autocomplete': 'list',
8078
'aria-owns': this.ids.menu,
@@ -89,8 +87,9 @@ $.widget( "ui.selectmenu", {
8987
.attr( 'role', 'combobox' );
9088

9189
// wrap and insert new button
92-
this.buttonWrap = $( '<span />' )
93-
.addClass( 'ui-selectmenu-button' )
90+
this.buttonWrap = $( '<span />', {
91+
'class': 'ui-selectmenu-button'
92+
})
9493
.append( this.button )
9594
.insertAfter( this.element );
9695
},
@@ -114,9 +113,10 @@ $.widget( "ui.selectmenu", {
114113
}
115114

116115
// 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+
})
120120
.append( this.menu )
121121
.appendTo( this.options.appendTo );
122122

@@ -146,7 +146,6 @@ $.widget( "ui.selectmenu", {
146146
if ( that.focus !== undefined && item.index != that.focus ) {
147147
that._trigger( "focus", event, { item: item } );
148148
}
149-
150149
that.focus = item.index;
151150
}
152151
})
@@ -158,7 +157,7 @@ $.widget( "ui.selectmenu", {
158157

159158
// document click closes menu
160159
this._bind( document, {
161-
'click': function( event ) {
160+
click: function( event ) {
162161
if ( this.isOpen && !$( event.target ).closest( "#" + this.ids.button).length ) {
163162
this.close( event );
164163
}
@@ -173,9 +172,10 @@ $.widget( "ui.selectmenu", {
173172
this._renderMenu( this.menu, this.items );
174173

175174
this.menu.menu( "refresh" );
175+
this.menuItems = this.menu.find( "li" ).not( '.ui-selectmenu-optgroup' );
176176

177177
// adjust ARIA
178-
this._getItems().find( 'a' ).attr( 'role', 'option' );
178+
this.menuItems.find( 'a' ).attr( 'role', 'option' );
179179
this._setSelected();
180180

181181
// set and transfer disabled state
@@ -280,7 +280,7 @@ $.widget( "ui.selectmenu", {
280280
_move: function( direction, event ) {
281281
if ( direction == "first" || direction == "last" ) {
282282
// 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 ]() );
284284
} else {
285285
// if menu is closed we need to focus the element first to indicate correct element
286286
if ( !this.isOpen ) {
@@ -297,11 +297,7 @@ $.widget( "ui.selectmenu", {
297297
},
298298

299299
_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 );
305301
},
306302

307303
_toggle: function( event ) {
@@ -355,7 +351,6 @@ $.widget( "ui.selectmenu", {
355351
break;
356352
case $.ui.keyCode.HOME:
357353
case $.ui.keyCode.PAGE_UP:
358-
console.log("test");
359354
this._move( "first", event );
360355
break;
361356
case $.ui.keyCode.END:
@@ -373,13 +368,14 @@ $.widget( "ui.selectmenu", {
373368
},
374369

375370
_setSelected: function() {
376-
var item = this._getSelectedItem().find("a");
371+
var item = this._getSelectedItem(),
372+
link = item.find("a");
377373
// update button text
378374
this.button.button( "option", "label", item.text() );
379375
// 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 );
383379
},
384380

385381
_setOption: function( key, value ) {
@@ -412,11 +408,7 @@ $.widget( "ui.selectmenu", {
412408
},
413409

414410
_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;
420412
},
421413

422414
_readOptions: function() {

0 commit comments

Comments
 (0)