]> source.dussan.org Git - jquery-ui.git/commitdiff
Spinner:
authorChi Cheng <cloudream@gmail.com>
Mon, 18 Aug 2008 11:37:19 +0000 (11:37 +0000)
committerChi Cheng <cloudream@gmail.com>
Mon, 18 Aug 2008 11:37:19 +0000 (11:37 +0000)
- handle quick click on div (shortor than 100ms)
- handle dblclick

ui/ui.spinner.js

index 3d17e054dd40cb6a22549a5beff7e129059c2df0..4bcb9e84337cc552dc8e1ada96962109bb7b2d30 100644 (file)
@@ -35,13 +35,15 @@ $.widget("ui.spinner", {
                        .prepend('<div class="ui-spinner-up"></div>')\r
                        .find("div.ui-spinner-up")\r
                                .bind("mousedown", function() { if(!self.counter) self.counter = 1; self._mousedown(100, "_up"); })\r
-                               .bind("mouseup", function(e) { self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self._propagate("change", e); })\r
+                               .bind("mouseup", function(e) { if(self.counter == 1) self._up(); self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self._propagate("change", e); })\r
+                               .bind("dblclick", function(e) { self._up(); })  // mousedown/mouseup capture first click, now handle second click\r
                                .css({ height: pickerHeight, top: parseInt(this.element.css("borderTopWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })\r
                        .end()\r
                        .append('<div class="ui-spinner-down"></div>')\r
                        .find("div.ui-spinner-down")\r
                                .bind("mousedown", function() { if(!self.counter) self.counter = 1; self._mousedown(100, "_down"); })\r
-                               .bind("mouseup", function(e) { self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self._propagate("change", e); })\r
+                               .bind("mouseup", function(e) { if(self.counter == 1) self._down(); self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self._propagate("change", e); })\r
+                               .bind("dblclick", function(e) { self._down(); })        // mousedown/mouseup capture first click, now handle second click\r
                                .css({ height: pickerHeight, bottom: parseInt(this.element.css("borderBottomWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })\r
                        .end()\r
                ;\r
@@ -71,19 +73,18 @@ $.widget("ui.spinner", {
                this.element[0].value = this.element[0].value.replace(/[^0-9\-]/g, '');\r
                this._constrain();\r
        },\r
-       _down: function(e) {\r
+       _spin: function(d ,e) {\r
                if(isNaN(parseInt(this.element[0].value,10))) this.element[0].value = this.options.start;\r
-               this.element[0].value -= (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping;\r
+               this.element[0].value = parseFloat(this.element[0].value) + ( d == "up" ? 1 : -1 ) * (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping;\r
                this._constrain();\r
                if(this.counter) this.counter++;\r
                this._propagate("spin", e);\r
        },\r
+       _down: function(e) {\r
+               this._spin("down", e);\r
+       },\r
        _up: function(e) {\r
-               if(isNaN(parseInt(this.element[0].value,10))) this.element[0].value = this.options.start;\r
-               this.element[0].value = parseFloat(this.element[0].value) + (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping;\r
-               this._constrain();\r
-               if(this.counter) this.counter++;\r
-               this._propagate("spin", e);\r
+               this._spin("up", e);\r
        },\r
        _mousedown: function(i, d) {\r
                var self = this;\r