From d31077469f6380c01308ccbbcc7580f9fadf82af Mon Sep 17 00:00:00 2001 From: Chi Cheng Date: Sat, 16 Aug 2008 05:55:17 +0000 Subject: [PATCH] Spinner: make internal methods internal, fixs #3207 functional demo fix(not associate with internal change) --- demos/functional/templates/ui.spinner.html | 4 +- ui/ui.spinner.js | 50 +++++++++++----------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/demos/functional/templates/ui.spinner.html b/demos/functional/templates/ui.spinner.html index 571163f2e..4ec12cc94 100644 --- a/demos/functional/templates/ui.spinner.html +++ b/demos/functional/templates/ui.spinner.html @@ -18,8 +18,8 @@ { desc: 'A spinner with min and max value', source: '$("#spinner").spinner({min:-100, max:150});' }, { desc: 'Big stepping', source: '$("#spinner").spinner({stepping:100});' }, { desc: 'Disable incremental option', source: '$("#spinner").spinner({incremental:false});' }, - { desc: 'Enable the spinner', source: '$("#spinner").attr("disabled","");' }, - { desc: 'Disable the spinner', source: '$("#spinner").attr("disabled","disabled");' } + { desc: 'Enable the spinner', source: '$("#spinner").spinner().attr("disabled","");' }, + { desc: 'Disable the spinner', source: '$("#spinner").spinner().attr("disabled","disabled");' } ] } diff --git a/ui/ui.spinner.js b/ui/ui.spinner.js index 8486f3ecf..536d3001c 100644 --- a/ui/ui.spinner.js +++ b/ui/ui.spinner.js @@ -34,14 +34,14 @@ $.widget("ui.spinner", { .css("float", this.element.css("float")) .prepend('
') .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); }) + .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('
') .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); }) + .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() ; @@ -49,60 +49,60 @@ $.widget("ui.spinner", { this.element .bind("keydown.spinner", function(e) { if(!self.counter) self.counter = 1; - self.keydown.call(self, e); + self._keydown.call(self, e); }) .bind("keyup.spinner", function(e) { self.counter = 0; - self.cleanUp(); - self.propagate("change", e); + self._cleanUp(); + self._propagate("change", e); }) ; if ($.fn.mousewheel) { - this.element.mousewheel(function(e, delta) { self.mousewheel(e, delta); }); + this.element.mousewheel(function(e, delta) { self._mousewheel(e, delta); }); } }, plugins: {}, - constrain: function() { + _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() { + _cleanUp: function() { this.element[0].value = this.element[0].value.replace(/[^0-9\-]/g, ''); - this.constrain(); + this._constrain(); }, - down: function(e) { + _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(); + this._constrain(); if(this.counter) this.counter++; - this.propagate("spin", e); + this._propagate("spin", e); }, - up: function(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(); + this._constrain(); if(this.counter) this.counter++; - this.propagate("spin", e); + this._propagate("spin", e); }, - mousedown: function(i, d) { + _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); + 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); + _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 }, - mousewheel: function(e, delta) { + _mousewheel: function(e, delta) { delta = ($.browser.opera ? -delta / Math.abs(delta) : delta); - delta > 0 ? this.up(e) : this.down(e); + delta > 0 ? this._up(e) : this._down(e); e.preventDefault(); }, ui: function(e) { @@ -112,7 +112,7 @@ $.widget("ui.spinner", { element: this.element }; }, - propagate: function(n,e) { + _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]); },