r2675 - Spinner: Fixed parsing of some options. Allow min and max to be defined as zero via attr...
Author: scott.gonzalez
Date: Sun Jun 7 18:14:04 2009
New Revision: 2675
Modified:
branches/dev/spinner/ui/ui.spinner.js
Log:
Spinner: Fixed parsing of some options. Allow min and max to be defined as
zero via attributes. Don't run readOnly through the parse function.
Modified: branches/dev/spinner/ui/ui.spinner.js
==============================================================================
--- branches/dev/spinner/ui/ui.spinner.js (original)
+++ branches/dev/spinner/ui/ui.spinner.js Sun Jun 7 18:14:04 2009
@@ -22,17 +22,14 @@
var self = this,
options = self.options,
validChars;
-
- function parse(val, ifNull) {
- if (val == null) {
- val = ifNull;
- }
+
+ function parse(val) {
if (typeof val == 'string') {
val = self._parseValue(val, options.radix, options.groupSeparator,
options.radixPoint);
}
return isNaN(val) ? null : val;
}
-
+
self._trigger('init', null, self.ui(null));
// initialize variables
@@ -64,12 +61,21 @@
}
self.validChars = validChars;
- // Parse min, max, step, and page for strings based on radix, apply
HTML5 attributes if they are null
- options.max = parse(options.max, self.element.attr('max') ||
Number.MAX_VALUE);
- options.min = parse(options.min, self.element.attr('min') ||
-Number.MAX_VALUE);
- options.page = parse(options.page);
- options.readOnly = parse(options.readOnly,
self.element.attr('readonly'));
- options.step = parse(options.step, self.element.attr('step')) || 1;
+ // parse min, max, step, and page based on radix
+ // min, max and step pull from attributes if the option is set to null
+ $.each({ min: -Number.MAX_VALUE, max: Number.MAX_VALUE, step: 1},
+ function(option, defaultValue) {
+ options[option] = parse(options[option] !== null
+ ? options[option]
+ : self.element.attr(option) !== undefined
+ ? self.element.attr(option)
+ : defaultValue);
+ });
+ options.page = parse(options.page || 1);
+
+ options.readOnly = options.readOnly !== null
+ ? options.readOnly
+ : self.element.attr('readonly');
// check for precision in steppinng and set _precision as internal
self._precision = parseInt(options.precision, 10);