mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Spinner: make internal methods internal, fixs #3207
functional demo fix(not associate with internal change)
This commit is contained in:
parent
44140343f4
commit
d31077469f
@ -18,8 +18,8 @@
|
|||||||
{ desc: 'A spinner with min and max value', source: '$("#spinner").spinner({min:-100, max:150});' },
|
{ desc: 'A spinner with min and max value', source: '$("#spinner").spinner({min:-100, max:150});' },
|
||||||
{ desc: 'Big stepping', source: '$("#spinner").spinner({stepping:100});' },
|
{ desc: 'Big stepping', source: '$("#spinner").spinner({stepping:100});' },
|
||||||
{ desc: 'Disable incremental option', source: '$("#spinner").spinner({incremental:false});' },
|
{ desc: 'Disable incremental option', source: '$("#spinner").spinner({incremental:false});' },
|
||||||
{ desc: 'Enable the spinner', source: '$("#spinner").attr("disabled","");' },
|
{ desc: 'Enable the spinner', source: '$("#spinner").spinner().attr("disabled","");' },
|
||||||
{ desc: 'Disable the spinner', source: '$("#spinner").attr("disabled","disabled");' }
|
{ desc: 'Disable the spinner', source: '$("#spinner").spinner().attr("disabled","disabled");' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,14 @@ $.widget("ui.spinner", {
|
|||||||
.css("float", this.element.css("float"))
|
.css("float", this.element.css("float"))
|
||||||
.prepend('<div class="ui-spinner-up"></div>')
|
.prepend('<div class="ui-spinner-up"></div>')
|
||||||
.find("div.ui-spinner-up")
|
.find("div.ui-spinner-up")
|
||||||
.bind("mousedown", function() { if(!self.counter) self.counter = 1; self.mousedown(100, "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("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 })
|
.css({ height: pickerHeight, top: parseInt(this.element.css("borderTopWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })
|
||||||
.end()
|
.end()
|
||||||
.append('<div class="ui-spinner-down"></div>')
|
.append('<div class="ui-spinner-down"></div>')
|
||||||
.find("div.ui-spinner-down")
|
.find("div.ui-spinner-down")
|
||||||
.bind("mousedown", function() { if(!self.counter) self.counter = 1; self.mousedown(100, "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("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 })
|
.css({ height: pickerHeight, bottom: parseInt(this.element.css("borderBottomWidth"),10)+1, right: parseInt(this.element.css("borderRightWidth"),10)+1 })
|
||||||
.end()
|
.end()
|
||||||
;
|
;
|
||||||
@ -49,60 +49,60 @@ $.widget("ui.spinner", {
|
|||||||
this.element
|
this.element
|
||||||
.bind("keydown.spinner", function(e) {
|
.bind("keydown.spinner", function(e) {
|
||||||
if(!self.counter) self.counter = 1;
|
if(!self.counter) self.counter = 1;
|
||||||
self.keydown.call(self, e);
|
self._keydown.call(self, e);
|
||||||
})
|
})
|
||||||
.bind("keyup.spinner", function(e) {
|
.bind("keyup.spinner", function(e) {
|
||||||
self.counter = 0;
|
self.counter = 0;
|
||||||
self.cleanUp();
|
self._cleanUp();
|
||||||
self.propagate("change", e);
|
self._propagate("change", e);
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
if ($.fn.mousewheel) {
|
if ($.fn.mousewheel) {
|
||||||
this.element.mousewheel(function(e, delta) { self.mousewheel(e, delta); });
|
this.element.mousewheel(function(e, delta) { self._mousewheel(e, delta); });
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
plugins: {},
|
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.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;
|
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.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;
|
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.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++;
|
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;
|
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.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++;
|
if(this.counter) this.counter++;
|
||||||
this.propagate("spin", e);
|
this._propagate("spin", e);
|
||||||
},
|
},
|
||||||
mousedown: function(i, d) {
|
_mousedown: function(i, d) {
|
||||||
var self = this;
|
var self = this;
|
||||||
i = i || 100;
|
i = i || 100;
|
||||||
if(this.timer) window.clearInterval(this.timer);
|
if(this.timer) window.clearInterval(this.timer);
|
||||||
this.timer = window.setInterval(function() {
|
this.timer = window.setInterval(function() {
|
||||||
self[d]();
|
self[d]();
|
||||||
if(self.counter > 20) self.mousedown(20, d);
|
if(self.counter > 20) self._mousedown(20, d);
|
||||||
}, i);
|
}, i);
|
||||||
},
|
},
|
||||||
keydown: function(e) {
|
_keydown: function(e) {
|
||||||
if(e.keyCode == 38 || e.keyCode == 39) this.up(e);
|
if(e.keyCode == 38 || e.keyCode == 39) this._up(e);
|
||||||
if(e.keyCode == 40 || e.keyCode == 37) this.down(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 == 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
|
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 = ($.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();
|
e.preventDefault();
|
||||||
},
|
},
|
||||||
ui: function(e) {
|
ui: function(e) {
|
||||||
@ -112,7 +112,7 @@ $.widget("ui.spinner", {
|
|||||||
element: this.element
|
element: this.element
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
propagate: function(n,e) {
|
_propagate: function(n,e) {
|
||||||
$.ui.plugin.call(this, n, [e, this.ui()]);
|
$.ui.plugin.call(this, n, [e, this.ui()]);
|
||||||
return this.element.triggerHandler(n == "spin" ? n : "spin"+n, [e, this.ui()], this.options[n]);
|
return this.element.triggerHandler(n == "spin" ? n : "spin"+n, [e, this.ui()], this.options[n]);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user