Skip to content

Commit 0a2fa95

Browse files
committed
Button: use the _classes method.
Fixes #7053
1 parent 4e4d44b commit 0a2fa95

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

tests/unit/button/button_common.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
TestHelpers.commonWidgetTests( "button", {
22
defaults: {
3+
classes: {
4+
"ui-button": "ui-corner-all",
5+
"ui-button-text": null,
6+
"ui-button-icons-only": null,
7+
"ui-button-icon-only": null,
8+
"ui-button-text-icons": null,
9+
"ui-button-text-icon-primary": null,
10+
"ui-button-text-icon-secondary": null,
11+
"ui-button-text-only": null
12+
},
313
disabled: null,
414
icons: {
515
primary: null,

tests/unit/button/button_core.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@
88
module("button: core");
99

1010
test("checkbox", function() {
11-
expect( 4 );
11+
expect( 5 );
1212
var input = $("#check"),
1313
label = $("label[for=check]");
1414
ok( input.is(":visible") );
1515
ok( label.is(":not(.ui-button)") );
1616
input.button();
1717
ok( input.is(".ui-helper-hidden-accessible") );
1818
ok( label.is(".ui-button") );
19+
ok( label.is(".ui-corner-all") );
1920
});
2021

2122
test("radios", function() {
22-
expect( 4 );
23+
expect( 5 );
2324
var inputs = $("#radio0 input"),
2425
labels = $("#radio0 label");
2526
ok( inputs.is(":visible") );
2627
ok( labels.is(":not(.ui-button)") );
2728
inputs.button();
2829
ok( inputs.is(".ui-helper-hidden-accessible") );
2930
ok( labels.is(".ui-button") );
31+
ok( labels.is(".ui-corner-all") );
3032
});
3133

3234
function assert(noForm, form1, form2) {

ui/button.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}(function( $ ) {
2626

2727
var lastActive,
28-
baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
28+
baseClasses = " ui-state-default ui-corner-all",
2929
typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only",
3030
formResetHandler = function() {
3131
var form = $( this );
@@ -55,6 +55,16 @@ $.widget( "ui.button", {
5555
version: "@VERSION",
5656
defaultElement: "<button>",
5757
options: {
58+
classes: {
59+
"ui-button": "ui-corner-all",
60+
"ui-button-text": null,
61+
"ui-button-icons-only": null,
62+
"ui-button-icon-only": null,
63+
"ui-button-text-icons": null,
64+
"ui-button-text-icon-primary": null,
65+
"ui-button-text-icon-secondary": null,
66+
"ui-button-text-only": null
67+
},
5868
disabled: null,
5969
text: true,
6070
label: null,
@@ -89,7 +99,7 @@ $.widget( "ui.button", {
8999
this._hoverable( this.buttonElement );
90100

91101
this.buttonElement
92-
.addClass( baseClasses )
102+
.addClass( this._classes( "ui-button" ) + baseClasses )
93103
.attr( "role", "button" )
94104
.bind( "mouseenter" + this.eventNamespace, function() {
95105
if ( options.disabled ) {
@@ -244,10 +254,10 @@ $.widget( "ui.button", {
244254
this.element
245255
.removeClass( "ui-helper-hidden-accessible" );
246256
this.buttonElement
247-
.removeClass( baseClasses + " ui-state-active " + typeClasses )
257+
.removeClass( this._classes( "ui-button " + typeClasses ) + baseClasses + " ui-state-active" )
248258
.removeAttr( "role" )
249259
.removeAttr( "aria-pressed" )
250-
.html( this.buttonElement.find(".ui-button-text").html() );
260+
.html( this.buttonElement.find( ".ui-button-text" ).html() );
251261

252262
if ( !this.hasTitle ) {
253263
this.buttonElement.removeAttr( "title" );
@@ -312,7 +322,7 @@ $.widget( "ui.button", {
312322
}
313323
var buttonElement = this.buttonElement.removeClass( typeClasses ),
314324
buttonText = $( "<span></span>", this.document[0] )
315-
.addClass( "ui-button-text" )
325+
.addClass( this._classes( "ui-button-text" ) )
316326
.html( this.options.label )
317327
.appendTo( buttonElement.empty() )
318328
.text(),
@@ -326,11 +336,11 @@ $.widget( "ui.button", {
326336
}
327337

328338
if ( icons.primary ) {
329-
buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" );
339+
buttonElement.prepend( "<span class='" + this._classes( "ui-button-icon-primary" ) + " ui-icon " + icons.primary + "'></span>" );
330340
}
331341

332342
if ( icons.secondary ) {
333-
buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" );
343+
buttonElement.append( "<span class='" + this._classes( "ui-button-icon-secondary" ) + " ui-icon " + icons.secondary + "'></span>" );
334344
}
335345

336346
if ( !this.options.text ) {
@@ -343,18 +353,21 @@ $.widget( "ui.button", {
343353
} else {
344354
buttonClasses.push( "ui-button-text-only" );
345355
}
346-
buttonElement.addClass( buttonClasses.join( " " ) );
356+
buttonElement.addClass( this._classes( buttonClasses.join( " " ) ) );
347357
}
348358
});
349359

350360
$.widget( "ui.buttonset", {
351361
version: "@VERSION",
352362
options: {
363+
classes: {
364+
"ui-buttonset": null
365+
},
353366
items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(ui-button)"
354367
},
355368

356369
_create: function() {
357-
this.element.addClass( "ui-buttonset" );
370+
this.element.addClass( this._classes( "ui-buttonset" ) );
358371
},
359372

360373
_init: function() {
@@ -384,6 +397,7 @@ $.widget( "ui.buttonset", {
384397
.map(function() {
385398
return $( this ).button( "widget" )[ 0 ];
386399
})
400+
// TODO: need to figure out how to use _classes here
387401
.removeClass( "ui-corner-all ui-corner-left ui-corner-right" )
388402
.filter( ":first" )
389403
.addClass( rtl ? "ui-corner-right" : "ui-corner-left" )

0 commit comments

Comments
 (0)