Skip to content

Commit e4c0f20

Browse files
committed
Spinner: Use _getCreateOptions() instead of custom _markupOptions().
1 parent c1da941 commit e4c0f20

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

tests/unit/spinner/spinner_defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ commonWidgetTests( "spinner", {
22
defaults: {
33
disabled: false,
44
incremental: true,
5-
max: null,
6-
min: null,
5+
max: Number.MAX_VALUE,
6+
min: -Number.MAX_VALUE,
77
numberFormat: null,
88
page: 10,
9-
step: null,
9+
step: 1,
1010
value: null,
1111

1212
// callbacks

ui/jquery.ui.spinner.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,33 @@ $.widget( "ui.spinner", {
1919
widgetEventPrefix: "spin",
2020
options: {
2121
incremental: true,
22-
max: null,
23-
min: null,
22+
max: Number.MAX_VALUE,
23+
min: -Number.MAX_VALUE,
2424
numberFormat: null,
2525
page: 10,
26-
step: null,
26+
step: 1,
2727
value: null
2828
},
2929

3030
_create: function() {
31-
this._markupOptions();
31+
this.value( this.options.value !== null ? this.options.value : this.element.val() || 0 );
3232
this._draw();
3333
this._mousewheel();
3434
this._aria();
3535
},
3636

37-
// TODO: should we use _getCreateOptions() now?
38-
// would increase overhead of init when options are specified,
39-
// but would move the defaults to the right location
40-
// and use our API the way it's meant to be used
41-
_markupOptions: function() {
42-
var that = this;
43-
$.each({
44-
min: -Number.MAX_VALUE,
45-
max: Number.MAX_VALUE,
46-
step: 1
47-
}, function( attr, defaultValue ) {
48-
if ( that.options[ attr ] === null ) {
49-
var value = that.element.attr( attr );
50-
that.options[ attr ] = typeof value === "string" && value.length > 0 ?
51-
that._parse( value ) :
52-
defaultValue;
37+
_getCreateOptions: function() {
38+
var options = {},
39+
element = this.element;
40+
41+
$.each( [ "min", "max", "step" ], function( i, option ) {
42+
var value = element.attr( option );
43+
if ( value !== undefined ) {
44+
options[ option ] = value;
5345
}
5446
});
55-
this.value( this.options.value !== null ? this.options.value : this.element.val() || 0 );
47+
48+
return options;
5649
},
5750

5851
_draw: function() {

0 commit comments

Comments
 (0)