Spinner: Refactored reading htlm5 attributes option init

This commit is contained in:
jzaefferer 2010-10-28 17:32:01 +02:00
parent 183fb69abf
commit 23157be9c3
2 changed files with 17 additions and 19 deletions

View File

@ -5,10 +5,10 @@
var spinner_defaults = { var spinner_defaults = {
disabled: false, disabled: false,
incremental: true, incremental: true,
max: Number.MAX_VALUE, max: null,
min: -Number.MAX_VALUE, min: null,
numberformat: null, numberformat: null,
step: 1, step: null,
value: null value: null
}; };

View File

@ -19,10 +19,10 @@ var pageModifier = 10;
$.widget('ui.spinner', { $.widget('ui.spinner', {
options: { options: {
incremental: true, incremental: true,
max: Number.MAX_VALUE, max: null,
min: -Number.MAX_VALUE, min: null,
numberformat: null, numberformat: null,
step: 1, step: null,
value: null value: null
}, },
@ -34,19 +34,17 @@ $.widget('ui.spinner', {
}, },
_markupOptions: function() { _markupOptions: function() {
// TODO refactor and read only when the related option is null (set default to null, init Number.MAX_VALUE only when nothing is specified) var _this = this;
var min = this.element.attr("min"); $.each({
if (typeof min == "string" && min.length > 0) { min: -Number.MAX_VALUE,
this.options.min = this._parse(min); max: Number.MAX_VALUE,
} step: 1
var max = this.element.attr("max"); }, function(attr, defaultValue) {
if (typeof max == "string" && max.length > 0) { if (_this.options[attr] === null) {
this.options.max = this._parse(max); var value = _this.element.attr(attr);
} _this.options[attr] = typeof value == "string" && value.length > 0 ? _this._parse(value) : defaultValue;
var step = this.element.attr("step"); }
if (typeof step == "string" && step.length > 0) { });
this.options.step = this._parse(step);
}
this.value(this.options.value !== null ? this.options.value : this.element.val() || 0); this.value(this.options.value !== null ? this.options.value : this.element.val() || 0);
}, },