diff options
author | Scott González <scott.gonzalez@gmail.com> | 2008-07-10 02:50:51 +0000 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2008-07-10 02:50:51 +0000 |
commit | 12cdae02b136f7a542dfac7319d008cf9c3d5505 (patch) | |
tree | 5face07144b2c77f390a03e96d9bdd710e152255 /ui/ui.spinner.js | |
parent | 4f412c60ea8dbf11b9447e838b815214ab3ca1a2 (diff) | |
download | jquery-ui-12cdae02b136f7a542dfac7319d008cf9c3d5505.tar.gz jquery-ui-12cdae02b136f7a542dfac7319d008cf9c3d5505.zip |
New plugins for 1.6: Fixed headers and indentation.
Diffstat (limited to 'ui/ui.spinner.js')
-rw-r--r-- | ui/ui.spinner.js | 230 |
1 files changed, 121 insertions, 109 deletions
diff --git a/ui/ui.spinner.js b/ui/ui.spinner.js index 064ec9aac..34f759982 100644 --- a/ui/ui.spinner.js +++ b/ui/ui.spinner.js @@ -1,114 +1,126 @@ +/*
+ * jQuery UI Spinner
+ *
+ * Copyright (c) 2008 jQuery
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ * http://docs.jquery.com/UI/Spinner
+ *
+ * Depends:
+ * ui.core.js
+ */
(function($) {
- $.widget("ui.spinner", {
- init: function() {
+$.widget("ui.spinner", {
+ init: function() {
- //Initialize needed constants
- var self = this;
- this.element.addClass("ui-spinner");
- this.element[0].value = this.options.start;
-
- var pickerHeight = this.element.innerHeight() / 2 - parseInt(this.element.css("borderTopWidth"),10) - 2;
- this.element
- .wrap("<div>")
- .parent()
- .css({
- position: this.element.css("position") == "static" ? "relative" : this.element.css("position"),
- left: this.element.css("left"),
- top: this.element.css("top"),
- width: this.element.outerWidth(),
- height: this.element.outerHeight()
- })
- .css("float", this.element.css("float"))
- .prepend('<div class="ui-spinner-up"></div>')
- .find("div.ui-spinner-up")
- .bind("mousedown", function() { if(!self.counter) self.counter = 1; self.mousedown(100, "up"); })
- .bind("mouseup", function(e) { self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self.propagate("change", e); })
- .css({ height: pickerHeight, top: parseInt(this.element.css("borderTopWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })
- .end()
- .append('<div class="ui-spinner-down"></div>')
- .find("div.ui-spinner-down")
- .bind("mousedown", function() { if(!self.counter) self.counter = 1; self.mousedown(100, "down"); })
- .bind("mouseup", function(e) { self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self.propagate("change", e); })
- .css({ height: pickerHeight, bottom: parseInt(this.element.css("borderBottomWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })
- .end()
- ;
-
- this.element
- .bind("keydown.spinner", function(e) {
- if(!self.counter) self.counter = 1;
- self.keydown.call(self, e);
+ //Initialize needed constants
+ var self = this;
+ this.element.addClass("ui-spinner");
+ this.element[0].value = this.options.start;
+
+ var pickerHeight = this.element.innerHeight() / 2 - parseInt(this.element.css("borderTopWidth"),10) - 2;
+ this.element
+ .wrap("<div>")
+ .parent()
+ .css({
+ position: this.element.css("position") == "static" ? "relative" : this.element.css("position"),
+ left: this.element.css("left"),
+ top: this.element.css("top"),
+ width: this.element.outerWidth(),
+ height: this.element.outerHeight()
})
- .bind("keyup.spinner", function(e) {
- self.counter = 0;
- self.cleanUp();
- self.propagate("change", e);
- })
- ;
+ .css("float", this.element.css("float"))
+ .prepend('<div class="ui-spinner-up"></div>')
+ .find("div.ui-spinner-up")
+ .bind("mousedown", function() { if(!self.counter) self.counter = 1; self.mousedown(100, "up"); })
+ .bind("mouseup", function(e) { self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self.propagate("change", e); })
+ .css({ height: pickerHeight, top: parseInt(this.element.css("borderTopWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })
+ .end()
+ .append('<div class="ui-spinner-down"></div>')
+ .find("div.ui-spinner-down")
+ .bind("mousedown", function() { if(!self.counter) self.counter = 1; self.mousedown(100, "down"); })
+ .bind("mouseup", function(e) { self.counter = 0; if(self.timer) window.clearInterval(self.timer); self.element[0].focus(); self.propagate("change", e); })
+ .css({ height: pickerHeight, bottom: parseInt(this.element.css("borderBottomWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })
+ .end()
+ ;
+
+ this.element
+ .bind("keydown.spinner", function(e) {
+ if(!self.counter) self.counter = 1;
+ self.keydown.call(self, e);
+ })
+ .bind("keyup.spinner", function(e) {
+ self.counter = 0;
+ self.cleanUp();
+ self.propagate("change", e);
+ })
+ ;
+
+ },
+ plugins: {},
+ constrain: function() {
+ if(this.options.min != undefined && this.element[0].value < this.options.min) this.element[0].value = this.options.min;
+ if(this.options.max != undefined && this.element[0].value > this.options.max) this.element[0].value = this.options.max;
+ },
+ cleanUp: function() {
+ this.element[0].value = this.element[0].value.replace(/[^0-9\-]/g, '');
+ this.constrain();
+ },
+ down: function(e) {
+ if(isNaN(parseInt(this.element[0].value,10))) this.element[0].value = this.options.start;
+ this.element[0].value -= (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping;
+ this.constrain();
+ if(this.counter) this.counter++;
+ this.propagate("spin", e);
+ },
+ up: function(e) {
+ if(isNaN(parseInt(this.element[0].value,10))) this.element[0].value = this.options.start;
+ this.element[0].value = parseFloat(this.element[0].value) + (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping;
+ this.constrain();
+ if(this.counter) this.counter++;
+ this.propagate("spin", e);
+ },
+ mousedown: function(i, d) {
+ var self = this;
+ i = i || 100;
+ if(this.timer) window.clearInterval(this.timer);
+ this.timer = window.setInterval(function() {
+ self[d]();
+ if(self.counter > 20) self.mousedown(20, d);
+ }, i);
+ },
+ keydown: function(e) {
+ if(e.keyCode == 38 || e.keyCode == 39) this.up(e);
+ if(e.keyCode == 40 || e.keyCode == 37) this.down(e);
+ if(e.keyCode == 36) this.element[0].value = this.options.min || this.options.start; //Home key goes to min, if defined, else to start
+ if(e.keyCode == 35 && this.options.max != undefined) this.element[0].value = this.options.max; //End key goes to maximum
+ },
+ ui: function(e) {
+ return {
+ instance: this,
+ options: this.options,
+ element: this.element
+ };
+ },
+ propagate: function(n,e) {
+ $.ui.plugin.call(this, n, [e, this.ui()]);
+ return this.element.triggerHandler(n == "spin" ? n : "spin"+n, [e, this.ui()], this.options[n]);
+ },
+ destroy: function() {
+ if(!$.data(this.element[0], 'spinner')) return;
+ this.element
+ .removeClass("ui-spinner ui-spinner-disabled")
+ .removeData("spinner")
+ .unbind(".spinner");
+ }
+});
+
+$.ui.spinner.defaults = {
+ stepping: 1,
+ start: 0,
+ incremental: true
+};
- },
- plugins: {},
- constrain: function() {
- if(this.options.min != undefined && this.element[0].value < this.options.min) this.element[0].value = this.options.min;
- if(this.options.max != undefined && this.element[0].value > this.options.max) this.element[0].value = this.options.max;
- },
- cleanUp: function() {
- this.element[0].value = this.element[0].value.replace(/[^0-9\-]/g, '');
- this.constrain();
- },
- down: function(e) {
- if(isNaN(parseInt(this.element[0].value,10))) this.element[0].value = this.options.start;
- this.element[0].value -= (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping;
- this.constrain();
- if(this.counter) this.counter++;
- this.propagate("spin", e);
- },
- up: function(e) {
- if(isNaN(parseInt(this.element[0].value,10))) this.element[0].value = this.options.start;
- this.element[0].value = parseFloat(this.element[0].value) + (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping;
- this.constrain();
- if(this.counter) this.counter++;
- this.propagate("spin", e);
- },
- mousedown: function(i, d) {
- var self = this;
- i = i || 100;
- if(this.timer) window.clearInterval(this.timer);
- this.timer = window.setInterval(function() {
- self[d]();
- if(self.counter > 20) self.mousedown(20, d);
- }, i);
- },
- keydown: function(e) {
- if(e.keyCode == 38 || e.keyCode == 39) this.up(e);
- if(e.keyCode == 40 || e.keyCode == 37) this.down(e);
- if(e.keyCode == 36) this.element[0].value = this.options.min || this.options.start; //Home key goes to min, if defined, else to start
- if(e.keyCode == 35 && this.options.max != undefined) this.element[0].value = this.options.max; //End key goes to maximum
- },
- ui: function(e) {
- return {
- instance: this,
- options: this.options,
- element: this.element
- };
- },
- propagate: function(n,e) {
- $.ui.plugin.call(this, n, [e, this.ui()]);
- return this.element.triggerHandler(n == "spin" ? n : "spin"+n, [e, this.ui()], this.options[n]);
- },
- destroy: function() {
- if(!$.data(this.element[0], 'spinner')) return;
- this.element
- .removeClass("ui-spinner ui-spinner-disabled")
- .removeData("spinner")
- .unbind(".spinner");
- }
- });
-
- $.ui.spinner.defaults = {
- stepping: 1,
- start: 0,
- incremental: true
- };
-
-})(jQuery);
\ No newline at end of file +})(jQuery);
|