Skip to content

Commit 5bdef55

Browse files
committed
Button: Updates based on new classes api
1 parent 67eed40 commit 5bdef55

File tree

3 files changed

+20
-49
lines changed

3 files changed

+20
-49
lines changed

tests/unit/button/button_common.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ TestHelpers.commonWidgetTests( "button", {
77
icon: null,
88
iconPosition: "beginning",
99
classes: {
10-
"ui-button": "ui-corner-all",
11-
"ui-button-icon-only": "",
12-
"ui-button-icon": ""
10+
"ui-button": "ui-corner-all"
1311
},
1412

1513
// Callbacks

tests/unit/button/button_common_deprecated.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ TestHelpers.commonWidgetTests( "button", {
1111
secondary: null
1212
},
1313
classes: {
14-
"ui-button": "ui-corner-all",
15-
"ui-button-icon-only": "",
16-
"ui-button-icon": ""
14+
"ui-button": "ui-corner-all"
1715
},
1816

1917
// Callbacks

ui/button.js

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
}
3030
}(function( $ ) {
3131

32-
var typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons" +
33-
" ui-button-text-only ui-icon-beginning ui-icon-end ui-icon-top ui-icon-bottom",
34-
formResetHandler = function() {
32+
var formResetHandler = function() {
3533
var form = $( this );
3634
setTimeout(function() {
3735
form.find( ".ui-button" ).filter( ":ui-button" ).button( "refresh" );
@@ -49,9 +47,7 @@ $.widget( "ui.button", {
4947
icon: null,
5048
iconPosition: "beginning",
5149
classes: {
52-
"ui-button": "ui-corner-all",
53-
"ui-button-icon-only": "",
54-
"ui-button-icon": ""
50+
"ui-button": "ui-corner-all"
5551
}
5652
},
5753

@@ -103,9 +99,8 @@ $.widget( "ui.button", {
10399
_enhance: function() {
104100
this._setOption( "disabled", this.options.disabled );
105101

106-
this.element
107-
.addClass( this._classes( "ui-button" ) + " ui-widget" )
108-
.attr( "role", "button" );
102+
this._addClass( "ui-button", " ui-widget" );
103+
this.element.attr( "role", "button" );
109104

110105
// Check to see if the label needs to be set or if its already correct
111106
if ( this.options.label && this.options.label !== this.originalLabel ) {
@@ -130,26 +125,24 @@ $.widget( "ui.button", {
130125

131126
_updateIcon: function( icon ) {
132127
if ( !this.icon ) {
133-
this.icon = $( "<span>" ).addClass( this._classes( "ui-button-icon" ) + " ui-icon" );
128+
this.icon = $( "<span>" );
129+
this._addClass( this.icon, "ui-button-icon", " ui-icon" );
134130

135131
if ( !this.options.showLabel ) {
136-
this.element.addClass( this._classes( "ui-button-icon-only" ) );
132+
this._addClass( "ui-button-icon-only" );
137133
} else {
138-
this.element.addClass( "ui-icon-" + this.options.iconPosition );
134+
this._addClass( null, "ui-icon-" + this.options.iconPosition );
139135
}
140136
} else {
141-
this.icon.removeClass( this.options.icon );
137+
this._removeClass( this.icon, null, this.options.icon );
142138
}
143-
144-
this.icon.addClass( icon ).appendTo( this.element );
139+
this._addClass( this.icon, null, icon );
140+
this.icon.appendTo( this.element );
145141
return this;
146142
},
147143

148144
_destroy: function() {
149-
this.element
150-
.removeClass( this._classes( "ui-button ui-button-icon-only" ) + " ui-widget" +
151-
" ui-state-active " + typeClasses )
152-
.removeAttr( "role" );
145+
this.element.removeAttr( "role" );
153146

154147
if ( this.icon ) {
155148
this.icon.remove();
@@ -159,46 +152,29 @@ $.widget( "ui.button", {
159152
}
160153
},
161154

162-
_elementsFromClassKey: function( classKey ) {
163-
switch ( classKey ) {
164-
case "ui-button-icon-only":
165-
if ( this.options.showLabel ) {
166-
return $();
167-
}
168-
break;
169-
case "ui-button-icon":
170-
if ( this.icon ) {
171-
return this.icon;
172-
}
173-
return $();
174-
default:
175-
return this._superApply( arguments );
176-
}
177-
},
178-
179155
_setOption: function( key, value ) {
180156
if ( key === "icon" ) {
181157
if ( value !== null ) {
182158
this._updateIcon( value );
183159
} else {
184160
this.icon.remove();
185-
this.element.removeClass( this._classes( "ui-button-icon" ) + " ui-icon-" +
186-
this.options.iconPosition );
161+
this._removeClass( "ui-button-icon", " ui-icon-" + this.options.iconPosition );
187162
}
188163
}
189164

190165
// Make sure we can't end up with a button that has no text nor icon
191166
if ( key === "showLabel" ) {
192167
if ( ( !value && this.options.icon ) || value ) {
193-
this.element.toggleClass( this._classes( "ui-button-icon-only" ), !value )
194-
.toggleClass( this.options.iconPosition, !!value );
168+
this._toggleClass( this._classes( "ui-button-icon-only" ), null, !value )
169+
._toggleClass( null, this.options.iconPosition, value );
195170
this._updateTooltip();
196171
} else {
197172
value = true;
198173
}
199174
}
200175
if ( key === "iconPosition" && this.options.icon ) {
201-
this.element.addClass( value ).removeClass( this.options.iconPosition );
176+
this._addClass( null, value )
177+
._removeClass( null, this.options.iconPosition );
202178
}
203179
if ( key === "label" ) {
204180
if ( this.isInput ) {
@@ -212,7 +188,7 @@ $.widget( "ui.button", {
212188
}
213189
this._super( key, value );
214190
if ( key === "disabled" ) {
215-
this.element.toggleClass( "ui-state-disabled", value )[ 0 ].disabled = value;
191+
this._toggleClass( null, "ui-state-disabled", value ).element[ 0 ].disabled = value;
216192
this.element.blur();
217193
}
218194
},
@@ -278,7 +254,6 @@ if ( $.uiBackCompat !== false ) {
278254
this.options.icons.primary = value;
279255
}
280256
if ( key === "icons" ) {
281-
this._setOption( "icon", value );
282257
if ( value.primary ) {
283258
this._setOption( "icon", value.primary );
284259
this._setOption( "iconPosition", "beginning" );

0 commit comments

Comments
 (0)