Skip to content

Commit a4445b6

Browse files
committed
Selectmenu: Implement new _addClass api
1 parent 357c4d4 commit a4445b6

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

ui/selectmenu.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ return $.widget( "ui.selectmenu", {
7676
},
7777

7878
_drawButton: function() {
79-
var that = this,
79+
var icon,
80+
that = this,
8081
item = this._parseOption(
8182
this.element.find( "option:selected" ),
8283
this.element[ 0 ].selectedIndex
@@ -107,13 +108,12 @@ return $.widget( "ui.selectmenu", {
107108
})
108109
.insertAfter( this.element );
109110

110-
this._addClass( this.button, "ui-selectmenu-button ui-selectmenu-button-closed",
111-
"ui-widget ui-state-default" );
111+
this._addClass( this.button,
112+
"ui-selectmenu-button ui-selectmenu-button-closed ui-widget ui-state-default" );
112113

113-
$( "<span>", {
114-
"class": "ui-icon " + this.options.icons.button
115-
})
116-
.prependTo( this.button );
114+
icon = $( "<span>" ).prependTo( this.button );
115+
116+
this._addClass( icon, "ui-icon " + this.options.icons.button );
117117

118118
this.buttonItem = this._renderButtonItem( item )
119119
.appendTo( this.button );
@@ -146,13 +146,9 @@ return $.widget( "ui.selectmenu", {
146146
});
147147

148148
// Wrap menu
149-
this.menuWrap = $( "<div>", {
150-
"class": "ui-selectmenu-menu ui-front"
151-
})
152-
.append( this.menu )
153-
.appendTo( this._appendTo() );
149+
this.menuWrap = $( "<div>" ).append( this.menu ).appendTo( this._appendTo() );
154150

155-
this._addClass( this.menuWrap, "ui-selectmenu-menu", "ui-front" );
151+
this._addClass( this.menuWrap, "ui-selectmenu-menu ui-front" );
156152

157153
// Initialize menu widget
158154
this.menuInstance = this.menu
@@ -255,7 +251,7 @@ return $.widget( "ui.selectmenu", {
255251
} else {
256252

257253
// Menu clears focus on close, reset focus to selected item
258-
this.menu.find( ".ui-state-focus" ).removeClass( "ui-state-focus" );
254+
this._removeClass( this.menu.find( ".ui-state-focus" ), "ui-state-focus" );
259255
this.menuInstance.focus( null, this._getSelectedItem() );
260256
}
261257

@@ -313,7 +309,7 @@ return $.widget( "ui.selectmenu", {
313309
text: item.optgroup
314310
}).appendTo( ul );
315311

316-
that._addClass( li, "ui-selectmenu-optgroup", "ui-menu-divider" +
312+
that._addClass( li, "ui-selectmenu-optgroup ui-menu-divider" +
317313
( item.element.parent( "optgroup" ).prop( "disabled" ) ?
318314
" ui-state-disabled" : "" ) );
319315

@@ -335,7 +331,7 @@ return $.widget( "ui.selectmenu", {
335331
});
336332

337333
if ( item.disabled ) {
338-
li.addClass( "ui-state-disabled" );
334+
this._addClass( li, "ui-state-disabled" );
339335
}
340336
this._setText( wrapper, item.label );
341337

@@ -533,9 +529,10 @@ return $.widget( "ui.selectmenu", {
533529

534530
_setOption: function( key, value ) {
535531
if ( key === "icons" ) {
536-
this.button.find( "span.ui-icon" )
537-
.removeClass( this.options.icons.button )
538-
.addClass( value.button );
532+
var icon = this.button.find( "span.ui-icon" );
533+
534+
this._removeClass( icon, this.options.icons.button );
535+
this._addClass( icon, value.button );
539536
}
540537

541538
this._super( key, value );
@@ -546,9 +543,8 @@ return $.widget( "ui.selectmenu", {
546543

547544
if ( key === "disabled" ) {
548545
this.menuInstance.option( "disabled", value );
549-
this.button
550-
.toggleClass( "ui-state-disabled", value )
551-
.attr( "aria-disabled", value );
546+
this.button.attr( "aria-disabled", value );
547+
this[ ( value ? "_add" : "_remove" ) + "Class" ]( "ui-state-disabled", value );
552548

553549
this.element.prop( "disabled", value );
554550
if ( value ) {
@@ -585,10 +581,7 @@ return $.widget( "ui.selectmenu", {
585581
},
586582

587583
_toggleAttr: function() {
588-
this.button
589-
.toggleClass( "ui-corner-top", this.isOpen )
590-
.toggleClass( "ui-corner-all", !this.isOpen )
591-
.attr( "aria-expanded", this.isOpen );
584+
this.button.attr( "aria-expanded", this.isOpen );
592585

593586
this[ ( !this.isOpen ? "_add" : "_remove" ) + "Class" ]
594587
( this.button, "ui-selectmenu-button-closed" );

0 commit comments

Comments
 (0)