mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Spinner: Fixed warnings.
This commit is contained in:
parent
78a2337faf
commit
6d39f52942
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
$.widget('ui.spinner', {
|
$.widget('ui.spinner', {
|
||||||
_init: function() {
|
_init: function() {
|
||||||
// terminate initialization if spinner already applied to current element
|
|
||||||
if($.data(this.element[0], 'spinner')) return;
|
|
||||||
|
|
||||||
// check for Init callback
|
|
||||||
this._trigger('init', null, this.ui(null));
|
this._trigger('init', null, this.ui(null));
|
||||||
|
|
||||||
// perform data bind on generic objects
|
// perform data bind on generic objects
|
||||||
@ -29,7 +25,7 @@ $.widget('ui.spinner', {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check for decimals in steppinng and set _decimals as internal
|
// check for decimals in steppinng and set _decimals as internal
|
||||||
this._decimals = parseInt(this.options.decimals);
|
this._decimals = parseInt(this.options.decimals, 10);
|
||||||
if (this.options.stepping.toString().indexOf('.') != -1) {
|
if (this.options.stepping.toString().indexOf('.') != -1) {
|
||||||
var s = this.options.stepping.toString();
|
var s = this.options.stepping.toString();
|
||||||
this._decimals = s.slice(s.indexOf('.')+1, s.length).length;
|
this._decimals = s.slice(s.indexOf('.')+1, s.length).length;
|
||||||
@ -51,12 +47,16 @@ $.widget('ui.spinner', {
|
|||||||
.find('.ui-spinner-up')
|
.find('.ui-spinner-up')
|
||||||
.bind('mousedown', function(e) {
|
.bind('mousedown', function(e) {
|
||||||
$(this).addClass('ui-spinner-pressed');
|
$(this).addClass('ui-spinner-pressed');
|
||||||
if(!self.counter) self.counter = 1;
|
if (!self.counter) {
|
||||||
|
self.counter = 1;
|
||||||
|
}
|
||||||
self._mousedown(100, '_up', e);
|
self._mousedown(100, '_up', e);
|
||||||
})
|
})
|
||||||
.bind('mouseup', function(e) {
|
.bind('mouseup', function(e) {
|
||||||
$(this).removeClass('ui-spinner-pressed');
|
$(this).removeClass('ui-spinner-pressed');
|
||||||
if(self.counter == 1) self._up(e);
|
if (self.counter == 1) {
|
||||||
|
self._up(e);
|
||||||
|
}
|
||||||
self._mouseup(e);
|
self._mouseup(e);
|
||||||
})
|
})
|
||||||
.bind('mouseout', function(e) {
|
.bind('mouseout', function(e) {
|
||||||
@ -72,7 +72,9 @@ $.widget('ui.spinner', {
|
|||||||
var KEYS = $.keyCode;
|
var KEYS = $.keyCode;
|
||||||
if (e.keyCode == KEYS.SPACE || e.keyCode == KEYS.ENTER) {
|
if (e.keyCode == KEYS.SPACE || e.keyCode == KEYS.ENTER) {
|
||||||
$(this).addClass('ui-spinner-pressed');
|
$(this).addClass('ui-spinner-pressed');
|
||||||
if(!self.counter) self.counter = 1;
|
if (!self.counter) {
|
||||||
|
self.counter = 1;
|
||||||
|
}
|
||||||
self._up.call(self, e);
|
self._up.call(self, e);
|
||||||
} else if (e.keyCode == KEYS.DOWN || e.keyCode == KEYS.RIGHT) {
|
} else if (e.keyCode == KEYS.DOWN || e.keyCode == KEYS.RIGHT) {
|
||||||
self.element.siblings('.ui-spinner-down').focus();
|
self.element.siblings('.ui-spinner-down').focus();
|
||||||
@ -90,12 +92,16 @@ $.widget('ui.spinner', {
|
|||||||
.find('.ui-spinner-down')
|
.find('.ui-spinner-down')
|
||||||
.bind('mousedown', function(e) {
|
.bind('mousedown', function(e) {
|
||||||
$(this).addClass('ui-spinner-pressed');
|
$(this).addClass('ui-spinner-pressed');
|
||||||
if(!self.counter) self.counter = 1;
|
if (!self.counter) {
|
||||||
|
self.counter = 1;
|
||||||
|
}
|
||||||
self._mousedown(100, '_down', e);
|
self._mousedown(100, '_down', e);
|
||||||
})
|
})
|
||||||
.bind('mouseup', function(e) {
|
.bind('mouseup', function(e) {
|
||||||
$(this).removeClass('ui-spinner-pressed');
|
$(this).removeClass('ui-spinner-pressed');
|
||||||
if(self.counter == 1) self._down();
|
if (self.counter == 1) {
|
||||||
|
self._down();
|
||||||
|
}
|
||||||
self._mouseup(e);
|
self._mouseup(e);
|
||||||
})
|
})
|
||||||
.bind('mouseout', function(e) {
|
.bind('mouseout', function(e) {
|
||||||
@ -111,7 +117,9 @@ $.widget('ui.spinner', {
|
|||||||
var KEYS = $.keyCode;
|
var KEYS = $.keyCode;
|
||||||
if (e.keyCode == KEYS.SPACE || e.keyCode == KEYS.ENTER) {
|
if (e.keyCode == KEYS.SPACE || e.keyCode == KEYS.ENTER) {
|
||||||
$(this).addClass('ui-spinner-pressed');
|
$(this).addClass('ui-spinner-pressed');
|
||||||
if(!self.counter) self.counter = 1;
|
if (!self.counter) {
|
||||||
|
self.counter = 1;
|
||||||
|
}
|
||||||
self._down.call(self, e);
|
self._down.call(self, e);
|
||||||
} else if (e.keyCode == KEYS.UP || e.keyCode == KEYS.LEFT) {
|
} else if (e.keyCode == KEYS.UP || e.keyCode == KEYS.LEFT) {
|
||||||
self.element.siblings('.ui-spinner-up').focus();
|
self.element.siblings('.ui-spinner-up').focus();
|
||||||
@ -146,7 +154,9 @@ $.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;
|
||||||
|
}
|
||||||
return self._keydown.call(self, e);
|
return self._keydown.call(self, e);
|
||||||
})
|
})
|
||||||
.bind('keyup.spinner', function(e) {
|
.bind('keyup.spinner', function(e) {
|
||||||
@ -165,21 +175,31 @@ $.widget('ui.spinner', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_constrain: function() {
|
_constrain: function() {
|
||||||
if(this.options.min != undefined && this._getValue() < this.options.min) this._setValue(this.options.min);
|
if (this.options.min != undefined && this._getValue() < this.options.min) {
|
||||||
if(this.options.max != undefined && this._getValue() > this.options.max) this._setValue(this.options.max);
|
this._setValue(this.options.min);
|
||||||
|
}
|
||||||
|
if (this.options.max != undefined && this._getValue() > this.options.max) {
|
||||||
|
this._setValue(this.options.max);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_cleanUp: function() {
|
_cleanUp: function() {
|
||||||
this._setValue(this._getValue());
|
this._setValue(this._getValue());
|
||||||
this._constrain();
|
this._constrain();
|
||||||
},
|
},
|
||||||
_spin: function(d, e) {
|
_spin: function(d, e) {
|
||||||
if (this.disabled) return;
|
if (this.disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(isNaN(this._getValue())) this._setValue(this.options.start);
|
if (isNaN(this._getValue())) {
|
||||||
|
this._setValue(this.options.start);
|
||||||
|
}
|
||||||
this._setValue(this._getValue() + (d == 'up' ? 1:-1) * (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping);
|
this._setValue(this._getValue() + (d == 'up' ? 1:-1) * (this.options.incremental && this.counter > 100 ? (this.counter > 200 ? 100 : 10) : 1) * this.options.stepping);
|
||||||
this._animate(d);
|
this._animate(d);
|
||||||
this._constrain();
|
this._constrain();
|
||||||
if(this.counter) this.counter++;
|
if (this.counter) {
|
||||||
|
this.counter++;
|
||||||
|
}
|
||||||
this._propagate('spin', e);
|
this._propagate('spin', e);
|
||||||
},
|
},
|
||||||
_down: function(e) {
|
_down: function(e) {
|
||||||
@ -193,25 +213,41 @@ $.widget('ui.spinner', {
|
|||||||
_mousedown: function(i, d, e) {
|
_mousedown: function(i, d, e) {
|
||||||
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](e);
|
self[d](e);
|
||||||
if(self.counter > 20) self._mousedown(20, d, e);
|
if (self.counter > 20) {
|
||||||
|
self._mousedown(20, d, e);
|
||||||
|
}
|
||||||
}, i);
|
}, i);
|
||||||
},
|
},
|
||||||
_mouseup: function(e) {
|
_mouseup: function(e) {
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
if(this.timer) window.clearInterval(this.timer);
|
if (this.timer) {
|
||||||
|
window.clearInterval(this.timer);
|
||||||
|
}
|
||||||
this.element[0].focus();
|
this.element[0].focus();
|
||||||
this._propagate('change', e);
|
this._propagate('change', e);
|
||||||
},
|
},
|
||||||
_keydown: function(e) {
|
_keydown: function(e) {
|
||||||
var KEYS = $.keyCode;
|
var KEYS = $.keyCode;
|
||||||
|
|
||||||
if(e.keyCode == KEYS.UP) this._up(e);
|
if (e.keyCode == KEYS.UP) {
|
||||||
if(e.keyCode == KEYS.DOWN) this._down(e);
|
this._up(e);
|
||||||
if(e.keyCode == KEYS.HOME) this._setValue(this.options.min || this.options.start); //Home key goes to min, if defined, else to start
|
}
|
||||||
if(e.keyCode == KEYS.END && this.options.max != undefined) this._setValue(this.options.max); //End key goes to maximum
|
if (e.keyCode == KEYS.DOWN) {
|
||||||
|
this._down(e);
|
||||||
|
}
|
||||||
|
if (e.keyCode == KEYS.HOME) {
|
||||||
|
//Home key goes to min, if defined, else to start
|
||||||
|
this._setValue(this.options.min || this.options.start);
|
||||||
|
}
|
||||||
|
if (e.keyCode == KEYS.END && this.options.max != undefined) {
|
||||||
|
//End key goes to maximum
|
||||||
|
this._setValue(this.options.max);
|
||||||
|
}
|
||||||
return (e.keyCode == KEYS.TAB || e.keyCode == KEYS.BACKSPACE ||
|
return (e.keyCode == KEYS.TAB || e.keyCode == KEYS.BACKSPACE ||
|
||||||
e.keyCode == KEYS.LEFT || e.keyCode == KEYS.RIGHT || e.keyCode == KEYS.PERIOD ||
|
e.keyCode == KEYS.LEFT || e.keyCode == KEYS.RIGHT || e.keyCode == KEYS.PERIOD ||
|
||||||
e.keyCode == KEYS.NUMPAD_DECIMAL || e.keyCode == KEYS.NUMPAD_SUBTRACT ||
|
e.keyCode == KEYS.NUMPAD_DECIMAL || e.keyCode == KEYS.NUMPAD_SUBTRACT ||
|
||||||
@ -220,14 +256,16 @@ $.widget('ui.spinner', {
|
|||||||
},
|
},
|
||||||
_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();
|
||||||
},
|
},
|
||||||
_getValue: function() {
|
_getValue: function() {
|
||||||
return parseFloat(this.element.val().replace(/[^0-9\-\.]/g, ''));
|
return parseFloat(this.element.val().replace(/[^0-9\-\.]/g, ''));
|
||||||
},
|
},
|
||||||
_setValue: function(newVal) {
|
_setValue: function(newVal) {
|
||||||
if(isNaN(newVal)) newVal = this.options.start;
|
if (isNaN(newVal)) {
|
||||||
|
newVal = this.options.start;
|
||||||
|
}
|
||||||
this.element.val(
|
this.element.val(
|
||||||
this.options.currency ?
|
this.options.currency ?
|
||||||
$.ui.spinner.format.currency(newVal, this.options.currency) :
|
$.ui.spinner.format.currency(newVal, this.options.currency) :
|
||||||
@ -251,7 +289,7 @@ $.widget('ui.spinner', {
|
|||||||
var html = obj; // string or object set it to html first
|
var html = obj; // string or object set it to html first
|
||||||
|
|
||||||
if (typeof obj == 'object') {
|
if (typeof obj == 'object') {
|
||||||
var format = (fmt != undefined) ? fmt : this.options.format;
|
var format = (fmt !== undefined ? fmt : this.options.format);
|
||||||
|
|
||||||
html = format.replace(/%(\(([^)]+)\))?/g,
|
html = format.replace(/%(\(([^)]+)\))?/g,
|
||||||
(function(data){
|
(function(data){
|
||||||
@ -263,7 +301,7 @@ $.widget('ui.spinner', {
|
|||||||
} else {
|
} else {
|
||||||
return data[lbl];
|
return data[lbl];
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
})(obj)
|
})(obj)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -285,7 +323,9 @@ $.widget('ui.spinner', {
|
|||||||
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]);
|
||||||
},
|
},
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
if(!$.data(this.element[0], 'spinner')) return;
|
if (!$.data(this.element[0], 'spinner')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ($.fn.mousewheel) {
|
if ($.fn.mousewheel) {
|
||||||
this.element.unmousewheel();
|
this.element.unmousewheel();
|
||||||
}
|
}
|
||||||
@ -358,5 +398,4 @@ $.extend($.ui.spinner, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
Loading…
Reference in New Issue
Block a user