r2944 - spinner: modified _getValue to handle null values; modified _spin to make this.counter st...

r2944 - spinner: modified _getValue to handle null values; modified _spin to make this.counter st...


Author: pazu2k@gmail.com
Date: Sun Jul 19 09:33:26 2009
New Revision: 2944
Added:
branches/dev/spinner/tests/visual/spinner/spinner_mousewheel.html
branches/dev/spinner/tests/visual/spinner/spinner_other_formats.html
Modified:
branches/dev/spinner/tests/unit/spinner/spinner.html
branches/dev/spinner/tests/visual/spinner/spinner.html
branches/dev/spinner/ui/ui.spinner.js
Log:
spinner: modified _getValue to handle null values; modified _spin to make
this.counter strict; refactored mousewheel code; minor refactor elsewhere.
Modified: branches/dev/spinner/tests/unit/spinner/spinner.html
==============================================================================
--- branches/dev/spinner/tests/unit/spinner/spinner.html    (original)
+++ branches/dev/spinner/tests/unit/spinner/spinner.html    Sun Jul 19
09:33:26 2009
@@ -9,8 +9,8 @@
    <link type="text/css" href="../testsuite.css" rel="stylesheet" />
    <script type="text/javascript" src="../testsuite.js"></script>
-    <script type="text/javascript"
src="../../../external/qunit/testrunner.js"></script>
-    <script type="text/javascript"
src="../../../external/simulate/jquery.simulate.js"></script>
+    <script type="text/javascript"
src="../../../external/testrunner-r6343.js"></script>
+    <script type="text/javascript"
src="../../../external/jquery.simulate-r6163.js"></script>
    <script type="text/javascript" src="spinner.js"></script>
    <script type="text/javascript" src="spinner_defaults.js"></script>
Modified: branches/dev/spinner/tests/visual/spinner/spinner.html
==============================================================================
--- branches/dev/spinner/tests/visual/spinner/spinner.html    (original)
+++ branches/dev/spinner/tests/visual/spinner/spinner.html    Sun Jul 19
09:33:26 2009
@@ -8,6 +8,7 @@
        input { width: 50px; }
    </style>
    <script type="text/javascript" src="../../../jquery-1.3.2.js"></script>
+    <script type="text/javascript"
src="../../../external/mousewheel/jquery.mousewheel.min.js"></script>
    <script type="text/javascript" src="../../../ui/ui.core.js"></script>
    <script type="text/javascript" src="../../../ui/ui.spinner.js"></script>
    <script type="text/javascript">
Added: branches/dev/spinner/tests/visual/spinner/spinner_mousewheel.html
==============================================================================
--- (empty file)
+++ branches/dev/spinner/tests/visual/spinner/spinner_mousewheel.html    Sun
Jul 19 09:33:26 2009
@@ -0,0 +1,22 @@
+<!doctype html>
+<html lang="en">
+<head>
+    <title>Spinner Visual Test : Mousewheel</title>
+    <link rel="stylesheet" href="../visual.css" type="text/css" />
+    <link rel="stylesheet" href="../../../themes/base/ui.all.css"
type="text/css">
+    <script type="text/javascript" src="../../../jquery-1.3.2.js"></script>
+    <script type="text/javascript"
src="../../../external/mousewheel/jquery.mousewheel.min.js"></script>
+    <script type="text/javascript" src="../../../ui/ui.core.js"></script>
+    <script type="text/javascript" src="../../../ui/ui.spinner.js"></script>
+    <script type="text/javascript">
+    $(function() {
+        $("#spinner").spinner();
+    });
+    </script>
+</head>
+<body>
+
+

<input id="spinner">


+
+</body>
+</html>
\ No newline at end of file
Added: branches/dev/spinner/tests/visual/spinner/spinner_other_formats.html
==============================================================================
--- (empty file)
+++ branches/dev/spinner/tests/visual/spinner/spinner_other_formats.html    
Sun Jul 19 09:33:26 2009
@@ -0,0 +1,22 @@
+<!doctype html>
+<html lang="en">
+<head>
+    <title>Spinner Visual Test : Other Formats</title>
+    <link rel="stylesheet" href="../visual.css" type="text/css" />
+    <link rel="stylesheet" href="../../../themes/base/ui.all.css"
type="text/css">
+    <script type="text/javascript" src="../../../jquery-1.3.2.js"></script>
+    <script type="text/javascript" src="../../../ui/ui.core.js"></script>
+    <script type="text/javascript" src="../../../ui/ui.spinner.js"></script>
+    <script type="text/javascript">
+    $(function() {
+        $("#hexadecimal").spinner({radix: 16});
+        $("#octadecimal").spinner({radix: 18});
+    });
+    </script>
+</head>
+<body>
+
+

<label>Hexadecimal:</label> <input id="hexadecimal">


+

<label>Octadecimal:</label> <input id="octadecimal">


+</body>
+</html>
\ No newline at end of file
Modified: branches/dev/spinner/ui/ui.spinner.js
==============================================================================
--- branches/dev/spinner/ui/ui.spinner.js    (original)
+++ branches/dev/spinner/ui/ui.spinner.js    Sun Jul 19 09:33:26 2009
@@ -59,10 +59,8 @@
            self._hide();
        }
-        if ($.fn.mousewheel && options.mouseWheel) {
-            self.element.mousewheel(self._mousewheel);
-        }
-        
+        self._mousewheel();
+                
        // disable spinner if element was already disabled
        if (self.element.attr("disabled")) {
            self.disable();
@@ -232,23 +230,19 @@
        if (!this.counter) {
            this.counter = 1;
        }
+        this.spinning = true;
        this._trigger('start', event, { value: this.value() });
    },
    _spin: function(step, event) {
        if (this.disabled) {
            return;
        }
-                
-        var value = this._getValue();
-
-        if (isNaN(value)) {
-            value = this.options.value;
+        if (!this.counter) {
+            this.counter = 1;
        }
-        this._setValue(value + (this.options.incremental && this.counter > 100 ?
(this.counter > 200 ? 100 : 10) : 1) * step);
+        this._setValue(this._getValue() + (this.options.incremental &&
this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * step);
        this._constrain();
-        if (this.counter) {
-            this.counter++;
-        }
+        this.counter++;
        
        this._trigger('spin', event, { value: this.value() });
    },
@@ -256,9 +250,9 @@
        this.counter = 0;
        if (this.timer) {
            window.clearInterval(this.timer);
-            this.timer = 0;
        }
        this.element[0].focus();
+        this.spinning = false;
        this._trigger('stop', event, { value: this.value() });
    },
    _change: function(event) {
@@ -269,7 +263,6 @@
        i = i || 100;
        if (this.timer) {
            window.clearInterval(this.timer);
-            this.timer = 0;
        }
        this.timer = window.setInterval(function() {
            self._spin(d*self.options.step, event);
@@ -309,19 +302,25 @@
        
        return false;
    },
-    _mousewheel: function(event, delta) {
-        // this = element, not widget, in event call
-        // we must use a function that is a member of the widget for
binding/unbinding the event on option changes
-        var self = $.data(this, 'spinner');
-        
-        delta = ($.browser.opera ? -delta / Math.abs(delta) : delta);
-        self._spin((delta > 0 ? 1 : -1) * self.options.step, event);
-        if (self.timeout) {
-            window.clearTimeout(self.timeout);
-            self.timeout = 0;
+    _mousewheel: function() {
+        var self = this;
+        if ($.fn.mousewheel && self.options.mouseWheel) {
+            this.element.mousewheel(function(event, delta) {
+                delta = ($.browser.opera ? -delta / Math.abs(delta) : delta);
+                if (!self.spinning) {
+                    self._start(event);
+                }
+                self._spin((delta > 0 ? 1 : -1) * self.options.step, event);
+                if (self.timeout) {
+                    window.clearTimeout(self.timeout);
+                }
+                self.timeout = window.setTimeout(function() {
+                    self._stop(event);
+                    self._change(event);
+                }, 400);
+                event.preventDefault();            
+            });            
        }
-        self.timeout = window.setTimeout(function(){self._change(event);}, 400);
-        event.preventDefault();
    },
    _parse: function(val) {
        if (typeof val == 'string') {
@@ -343,7 +342,8 @@
        return isNaN(val) ? null : val;
    },
    _getValue: function() {
-        return this._parse(this.element.val());
+        var value = this._parse(this.element.val());
+        return isNaN(value) ? this.options.value : value;
    },
    _setValue: function(newVal) {
        if (isNaN(newVal)) {
@@ -400,9 +400,7 @@
        return this;
    },
    _setData: function(key, value) {
-        if ((key == 'mouseWheel') && (value != this.options.mouseWheel) &&
$.fn.mousewheel) {
-            this.element[value ? 'mousewheel' : 'unmousewheel'](this._mousewheel);
-        } else if (key == 'hide') {
+        if (key == 'hide') {
            if (typeof value != 'boolean') {
                this[this.hovered || this.focused ? '_show' : '_hide']();
            } else if (value) {