Skip to content

Commit d6ffcf4

Browse files
committed
Spinner: Deprecate _uiSpinnerHtml and _buttonHtml extension points
Fixes #11097 Closes gh-1560
1 parent 1a39db0 commit d6ffcf4

File tree

4 files changed

+106
-12
lines changed

4 files changed

+106
-12
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
define( [
2+
"lib/common",
3+
"ui/spinner"
4+
], function( common ) {
5+
6+
common.testWidget( "spinner", {
7+
defaults: {
8+
classes: {
9+
"ui-spinner": "ui-corner-all",
10+
"ui-spinner-up": "ui-corner-tr",
11+
"ui-spinner-down": "ui-corner-br"
12+
},
13+
culture: null,
14+
disabled: false,
15+
icons: {
16+
down: "ui-icon-triangle-1-s",
17+
up: "ui-icon-triangle-1-n"
18+
},
19+
incremental: true,
20+
max: null,
21+
min: null,
22+
numberFormat: null,
23+
page: 10,
24+
step: 1,
25+
26+
// callbacks
27+
change: null,
28+
create: null,
29+
spin: null,
30+
start: null,
31+
stop: null
32+
}
33+
});
34+
35+
} );

tests/unit/spinner/deprecated.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>jQuery UI Spinner Test Suite</title>
6+
7+
<script src="../../../external/requirejs/require.js"></script>
8+
<script src="../../lib/css.js" data-modules="core button spinner"></script>
9+
<script src="../../lib/bootstrap.js" data-widget="spinner" data-deprecated="true"></script>
10+
</head>
11+
<body>
12+
13+
<div id="qunit"></div>
14+
<div id="qunit-fixture">
15+
16+
<input id="spin" class="foo">
17+
<input id="spin2" value="2">
18+
19+
</div>
20+
</body>
21+
</html>

tests/unit/spinner/deprecated.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
define( [
2+
"jquery",
3+
"ui/spinner"
4+
], function( $ ) {
5+
6+
var originalSpinner = $.ui.spinner.prototype;
7+
module( "spinner: deprecated", {
8+
setup: function() {
9+
$.widget( "ui.spinner", $.ui.spinner, {
10+
_uiSpinnerHtml: function() {
11+
return "<span class='spin-wrap'>";
12+
},
13+
14+
_buttonHtml: function() {
15+
return "" +
16+
"<a class='spin-up'>" +
17+
"<span>&#9650;</span>" +
18+
"</a>" +
19+
"<a>" +
20+
"<span>&#9660;</span>" +
21+
"</a>";
22+
}
23+
} );
24+
},
25+
26+
teardown: function() {
27+
$.ui.spinner.prototype = originalSpinner;
28+
}
29+
} );
30+
31+
test( "markup structure - custom", function( assert ) {
32+
expect( 2 );
33+
var element = $( "#spin" ).spinner(),
34+
spinner = element.spinner( "widget" ),
35+
up = spinner.find( ".ui-spinner-up" );
36+
37+
assert.hasClasses( spinner, "ui-spinner ui-widget ui-widget-content spin-wrap", "_uiSpinnerHtml() overides default markup" );
38+
assert.hasClasses( up, "ui-spinner-button ui-spinner-up ui-widget spin-up", "_ButtonHtml() overides default markup" );
39+
} );
40+
41+
} );

ui/spinner.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ $.widget( "ui.spinner", {
221221
.wrap( "<span>" )
222222
.parent()
223223

224-
// add buttons
225-
.append( "" +
224+
// Add buttons
225+
.append(
226226
"<a>" +
227227
"<span>&#9650;</span>" +
228228
"</a>" +
229229
"<a>" +
230230
"<span>&#9660;</span>" +
231-
"</a>"; );
231+
"</a>" );
232232
},
233233

234234
_draw: function() {
@@ -256,9 +256,9 @@ $.widget( "ui.spinner", {
256256

257257
// IE 6 doesn't understand height: 50% for the buttons
258258
// unless the wrapper has an explicit height
259-
if ( this.buttons.height() > Math.ceil( uiSpinner.height() * 0.5 ) &&
260-
uiSpinner.height() > 0 ) {
261-
uiSpinner.height( uiSpinner.height() );
259+
if ( this.buttons.height() > Math.ceil( this.uiSpinner.height() * 0.5 ) &&
260+
this.uiSpinner.height() > 0 ) {
261+
this.uiSpinner.height( this.uiSpinner.height() );
262262
}
263263

264264
// disable spinner if element was already disabled
@@ -535,18 +535,16 @@ $.widget( "ui.spinner", {
535535
// TODO: switch return back to widget declaration at top of file when this is removed
536536
if ( $.uiBackCompat !== false ) {
537537

538-
// Backcompat for dialogClass option
538+
// Backcompat for spinner html extension points
539539
$.widget( "ui.spinner", $.ui.spinner, {
540-
_enhance: function(){
541-
var uiSpinner = this.uiSpinner = this.element
540+
_enhance: function() {
541+
this.uiSpinner = this.element
542542
.attr( "autocomplete", "off" )
543543
.wrap( this._uiSpinnerHtml() )
544544
.parent()
545545

546546
// Add buttons
547547
.append( this._buttonHtml() );
548-
549-
this.element.attr( "role", "spinbutton" );
550548
},
551549
_uiSpinnerHtml: function() {
552550
return "<span>";
@@ -566,5 +564,4 @@ if ( $.uiBackCompat !== false ) {
566564

567565
return $.ui.spinner;
568566

569-
570567
} ) );

0 commit comments

Comments
 (0)