29
29
}
30
30
} ( function ( $ ) {
31
31
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 ( ) {
35
33
var form = $ ( this ) ;
36
34
setTimeout ( function ( ) {
37
35
form . find ( ".ui-button" ) . filter ( ":ui-button" ) . button ( "refresh" ) ;
@@ -49,9 +47,7 @@ $.widget( "ui.button", {
49
47
icon : null ,
50
48
iconPosition : "beginning" ,
51
49
classes : {
52
- "ui-button" : "ui-corner-all" ,
53
- "ui-button-icon-only" : "" ,
54
- "ui-button-icon" : ""
50
+ "ui-button" : "ui-corner-all"
55
51
}
56
52
} ,
57
53
@@ -103,9 +99,8 @@ $.widget( "ui.button", {
103
99
_enhance : function ( ) {
104
100
this . _setOption ( "disabled" , this . options . disabled ) ;
105
101
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" ) ;
109
104
110
105
// Check to see if the label needs to be set or if its already correct
111
106
if ( this . options . label && this . options . label !== this . originalLabel ) {
@@ -130,26 +125,24 @@ $.widget( "ui.button", {
130
125
131
126
_updateIcon : function ( icon ) {
132
127
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" ) ;
134
130
135
131
if ( ! this . options . showLabel ) {
136
- this . element . addClass ( this . _classes ( "ui-button-icon-only" ) ) ;
132
+ this . _addClass ( "ui-button-icon-only" ) ;
137
133
} else {
138
- this . element . addClass ( "ui-icon-" + this . options . iconPosition ) ;
134
+ this . _addClass ( null , "ui-icon-" + this . options . iconPosition ) ;
139
135
}
140
136
} else {
141
- this . icon . removeClass ( this . options . icon ) ;
137
+ this . _removeClass ( this . icon , null , this . options . icon ) ;
142
138
}
143
-
144
- this . icon . addClass ( icon ) . appendTo ( this . element ) ;
139
+ this . _addClass ( this . icon , null , icon ) ;
140
+ this . icon . appendTo ( this . element ) ;
145
141
return this ;
146
142
} ,
147
143
148
144
_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" ) ;
153
146
154
147
if ( this . icon ) {
155
148
this . icon . remove ( ) ;
@@ -159,46 +152,29 @@ $.widget( "ui.button", {
159
152
}
160
153
} ,
161
154
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
-
179
155
_setOption : function ( key , value ) {
180
156
if ( key === "icon" ) {
181
157
if ( value !== null ) {
182
158
this . _updateIcon ( value ) ;
183
159
} else {
184
160
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 ) ;
187
162
}
188
163
}
189
164
190
165
// Make sure we can't end up with a button that has no text nor icon
191
166
if ( key === "showLabel" ) {
192
167
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 ) ;
195
170
this . _updateTooltip ( ) ;
196
171
} else {
197
172
value = true ;
198
173
}
199
174
}
200
175
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 ) ;
202
178
}
203
179
if ( key === "label" ) {
204
180
if ( this . isInput ) {
@@ -212,7 +188,7 @@ $.widget( "ui.button", {
212
188
}
213
189
this . _super ( key , value ) ;
214
190
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 ;
216
192
this . element . blur ( ) ;
217
193
}
218
194
} ,
@@ -278,7 +254,6 @@ if ( $.uiBackCompat !== false ) {
278
254
this . options . icons . primary = value ;
279
255
}
280
256
if ( key === "icons" ) {
281
- this . _setOption ( "icon" , value ) ;
282
257
if ( value . primary ) {
283
258
this . _setOption ( "icon" , value . primary ) ;
284
259
this . _setOption ( "iconPosition" , "beginning" ) ;
0 commit comments