Skip to content

Commit 1efca9c

Browse files
committed
Spinner: Implement new _addClass api
1 parent 62c80ad commit 1efca9c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

ui/spinner.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,23 @@ return $.widget( "ui.spinner", {
216216
// add buttons
217217
.append( this._buttonHtml() );
218218

219-
this._addClass( this.uiSpinner, "ui-spinner", "ui-widget ui-widget-content" );
219+
this._addClass( this.uiSpinner, "ui-spinner ui-widget ui-widget-content" );
220220
this._addClass( "ui-spinner-input" );
221221

222222
this.element.attr( "role", "spinbutton" );
223223

224224
// button bindings
225225
this.buttons = uiSpinner.find( "a" )
226226
.attr( "tabIndex", -1 )
227-
.button()
227+
.button();
228228

229229
// Right now button does not support classes once it does adjust this with classes
230-
.removeClass( "ui-corner-all" );
230+
this._removeClass( this.buttons, "ui-corner-all" );
231231

232232
this._addClass( this.buttons.eq( 0 ), "ui-spinner-button ui-spinner-up" );
233233
this._addClass( this.buttons.eq( 1 ), "ui-spinner-button ui-spinner-down" );
234+
this._addClass( this.buttons.first().find( "span span" ), "ui-icon " + this.options.icons.up );
235+
this._addClass( this.buttons.last().find( "span span" ), "ui-icon " + this.options.icons.down );
234236

235237
// IE 6 doesn't understand height: 50% for the buttons
236238
// unless the wrapper has an explicit height
@@ -268,16 +270,16 @@ return $.widget( "ui.spinner", {
268270
},
269271

270272
_uiSpinnerHtml: function() {
271-
return "<span class='ui-spinner ui-widget ui-widget-content ui-corner-all'></span>";
273+
return "<span></span>";
272274
},
273275

274276
_buttonHtml: function() {
275277
return "" +
276278
"<a>" +
277-
"<span class='ui-icon " + this.options.icons.up + "'>&#9650;</span>" +
279+
"<span>&#9650;</span>" +
278280
"</a>" +
279281
"<a>" +
280-
"<span class='ui-icon " + this.options.icons.down + "'>&#9660;</span>" +
282+
"<span>&#9660;</span>" +
281283
"</a>";
282284
},
283285

@@ -385,8 +387,9 @@ return $.widget( "ui.spinner", {
385387
},
386388

387389
_setOption: function( key, value ) {
390+
var prevValue, first, last;
388391
if ( key === "culture" || key === "numberFormat" ) {
389-
var prevValue = this._parse( this.element.val() );
392+
prevValue = this._parse( this.element.val() );
390393
this.options[ key ] = value;
391394
this.element.val( this._format( prevValue ) );
392395
return;
@@ -398,18 +401,19 @@ return $.widget( "ui.spinner", {
398401
}
399402
}
400403
if ( key === "icons" ) {
401-
this.buttons.first().find( ".ui-icon" )
402-
.removeClass( this.options.icons.up )
403-
.addClass( value.up );
404-
this.buttons.last().find( ".ui-icon" )
405-
.removeClass( this.options.icons.down )
406-
.addClass( value.down );
404+
first = this.buttons.first().find( ".ui-icon" );
405+
this._removeClass( first, this.options.icons.up );
406+
this._addClass( first, value.up );
407+
last = this.buttons.last().find( ".ui-icon" );
408+
this._removeClass( last, this.options.icons.down );
409+
this._addClass( last, value.down );
407410
}
408411

409412
this._super( key, value );
410413

411414
if ( key === "disabled" ) {
412-
this.widget().toggleClass( "ui-state-disabled", !!value );
415+
this[ ( !!value ? "_add" : "_remove" ) + "Class" ]( this.widget(),
416+
"ui-state-disabled" );
413417
this.element.prop( "disabled", !!value );
414418
this.buttons.button( value ? "disable" : "enable" );
415419
}
@@ -482,7 +486,6 @@ return $.widget( "ui.spinner", {
482486
.removeAttr( "aria-valuemax" )
483487
.removeAttr( "aria-valuenow" );
484488

485-
this._removeClass( "ui-spinner-input" );
486489
this.uiSpinner.replaceWith( this.element );
487490
},
488491

0 commit comments

Comments
 (0)