Skip to content

Commit 23157be

Browse files
committed
Spinner: Refactored reading htlm5 attributes option init
1 parent 183fb69 commit 23157be

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

tests/unit/spinner/spinner_defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
var spinner_defaults = {
66
disabled: false,
77
incremental: true,
8-
max: Number.MAX_VALUE,
9-
min: -Number.MAX_VALUE,
8+
max: null,
9+
min: null,
1010
numberformat: null,
11-
step: 1,
11+
step: null,
1212
value: null
1313
};
1414

ui/jquery.ui.spinner.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ var pageModifier = 10;
1919
$.widget('ui.spinner', {
2020
options: {
2121
incremental: true,
22-
max: Number.MAX_VALUE,
23-
min: -Number.MAX_VALUE,
22+
max: null,
23+
min: null,
2424
numberformat: null,
25-
step: 1,
25+
step: null,
2626
value: null
2727
},
2828

@@ -34,19 +34,17 @@ $.widget('ui.spinner', {
3434
},
3535

3636
_markupOptions: function() {
37-
// TODO refactor and read only when the related option is null (set default to null, init Number.MAX_VALUE only when nothing is specified)
38-
var min = this.element.attr("min");
39-
if (typeof min == "string" && min.length > 0) {
40-
this.options.min = this._parse(min);
41-
}
42-
var max = this.element.attr("max");
43-
if (typeof max == "string" && max.length > 0) {
44-
this.options.max = this._parse(max);
45-
}
46-
var step = this.element.attr("step");
47-
if (typeof step == "string" && step.length > 0) {
48-
this.options.step = this._parse(step);
49-
}
37+
var _this = this;
38+
$.each({
39+
min: -Number.MAX_VALUE,
40+
max: Number.MAX_VALUE,
41+
step: 1
42+
}, function(attr, defaultValue) {
43+
if (_this.options[attr] === null) {
44+
var value = _this.element.attr(attr);
45+
_this.options[attr] = typeof value == "string" && value.length > 0 ? _this._parse(value) : defaultValue;
46+
}
47+
});
5048
this.value(this.options.value !== null ? this.options.value : this.element.val() || 0);
5149
},
5250

0 commit comments

Comments
 (0)