From 12cdae02b136f7a542dfac7319d008cf9c3d5505 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 10 Jul 2008 02:50:51 +0000 Subject: New plugins for 1.6: Fixed headers and indentation. --- ui/ui.autocomplete.js | 23 ++-- ui/ui.history.js | 179 +++++++++++++------------- ui/ui.magnifier.js | 298 +++++++++++++++++++++--------------------- ui/ui.progressbar.js | 348 +++++++++++++++++++++++++------------------------- ui/ui.spinner.js | 230 +++++++++++++++++---------------- 5 files changed, 546 insertions(+), 532 deletions(-) diff --git a/ui/ui.autocomplete.js b/ui/ui.autocomplete.js index 19a51451a..8476c5c1d 100644 --- a/ui/ui.autocomplete.js +++ b/ui/ui.autocomplete.js @@ -1,18 +1,16 @@ /* - * Autocomplete - jQuery plugin 1.0.1 + * jQuery UI Autocomplete * - * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer - * - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - * - * Revision: $Id: jquery.autocomplete.js 5698 2008-05-27 13:53:30Z paul.bakaus $ + * Copyright (c) 2007, 2008 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * http://docs.jquery.com/UI/Autocomplete * + * Depends: + * ui.core.js */ - -;(function($) { - +(function($) { $.widget("ui.autocomplete", { @@ -47,7 +45,6 @@ $.widget("ui.autocomplete", { }); - $.Autocompleter = function(input, options) { var KEY = { @@ -772,4 +769,4 @@ $.Autocompleter.Selection = function(field, start, end) { field.focus(); }; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/ui/ui.history.js b/ui/ui.history.js index 6378b75a0..40848ebe5 100644 --- a/ui/ui.history.js +++ b/ui/ui.history.js @@ -7,111 +7,106 @@ * * http://docs.jquery.com/UI/History * - * Revision: $Id: ui.history.js 5218 2008-04-09 20:08:24Z rdworth $ + * Depends: + * ui.core.js */ -;(function($) { +(function($) { - // if the UI scope is not availalable, add it - $.ui = $.ui || {}; +// TODO lazy loading singleton +$.ui.hmanager = new function() { + var states = {}, def = function() {}; - // TODO lazy loading singleton - $.ui.hmanager = new function() { - var states = {}, def = function() {}; - - var $window = $(window), hash = location.hash; - - function getState() { - return hash.replace('#', ''); - } - - var iframe; - // var keepHistoryIn = iframe || window; - - return { + var $window = $(window), hash = location.hash; - enable: function() { - - if ($.browser.msie && parseInt($.browser.version) < 8) { - $(function() { - // create hidden iframe for hash change tracking - iframe = $(''). - prependTo(document.body)[0]; - - // create initial history entry - iframe.contentWindow.document.open(); - iframe.contentWindow.document.close(); - - if (getState()) - iframe.contentWindow.document.location.hash = getState(); - - }); - } - - $window.bind('hashchange', function(e) { - // Prevent IE 8 from fireing an event twice, - // one from true event, one from trigger... - if (!iframe && hash == location.hash || iframe && hash == iframe.contentWindow.document.location.hash) - return false; + function getState() { + return hash.replace('#', ''); + } + + var iframe; + // var keepHistoryIn = iframe || window; + + return { - if ($.browser.msie && parseInt($.browser.version) < 8) { - hash = iframe.contentWindow.document.location.hash; - } - else - hash = location.hash; + enable: function() { + + if ($.browser.msie && parseInt($.browser.version) < 8) { + $(function() { + // create hidden iframe for hash change tracking + iframe = $(''). + prependTo(document.body)[0]; + + // create initial history entry + iframe.contentWindow.document.open(); + iframe.contentWindow.document.close(); if (getState()) - states[getState()](); - else - // TODO invoke default - ; + iframe.contentWindow.document.location.hash = getState(); + }); - - if (!($.browser.msie && parseInt($.browser.version) >= 8)) { - setInterval( - ($.browser.msie ? - function() { - if (hash != iframe.contentWindow.document.location.hash) - $window.trigger('hashchange'); - } : - function() { - if (hash != location.hash) - $window.trigger('hashchange'); - else - // Do the history.length check hack for Safari 2 - ; - } - ) - , 200 - ); + } + + $window.bind('hashchange', function(e) { + // Prevent IE 8 from fireing an event twice, + // one from true event, one from trigger... + if (!iframe && hash == location.hash || iframe && hash == iframe.contentWindow.document.location.hash) + return false; + + if ($.browser.msie && parseInt($.browser.version) < 8) { + hash = iframe.contentWindow.document.location.hash; } + else + hash = location.hash; - }, - - add: function(state, handler) { - states[state] = handler; - }, + if (getState()) + states[getState()](); + else + // TODO invoke default + ; + }); - go: function(state) { - if (state) { - if ($.browser.msie && parseInt($.browser.version) < 8) { - iframe.contentWindow.document.open(); - iframe.contentWindow.document.close(); - iframe.contentWindow.document.location.hash = state; - } - location.hash = state; - $window.trigger('hashchange'); - } - else - console.log('TODO do default state'); + if (!($.browser.msie && parseInt($.browser.version) >= 8)) { + setInterval( + ($.browser.msie ? + function() { + if (hash != iframe.contentWindow.document.location.hash) + $window.trigger('hashchange'); + } : + function() { + if (hash != location.hash) + $window.trigger('hashchange'); + else + // Do the history.length check hack for Safari 2 + ; + } + ) + , 200 + ); } + }, - } + add: function(state, handler) { + states[state] = handler; + }, - }; + go: function(state) { + if (state) { + if ($.browser.msie && parseInt($.browser.version) < 8) { + iframe.contentWindow.document.open(); + iframe.contentWindow.document.close(); + iframe.contentWindow.document.location.hash = state; + } + location.hash = state; + $window.trigger('hashchange'); + } + else + console.log('TODO do default state'); + } + } +}; + +$.ui.history = function() { + var args = Array.prototype.slice.call(arguments, 1); + $.ui.hmanager[arguments[0]].apply($.ui.hmanager, args); +}; - $.ui.history = function() { - var args = Array.prototype.slice.call(arguments, 1); - $.ui.hmanager[arguments[0]].apply($.ui.hmanager, args); - }; - })(jQuery); diff --git a/ui/ui.magnifier.js b/ui/ui.magnifier.js index 2adf7ed52..e40e6f3f4 100644 --- a/ui/ui.magnifier.js +++ b/ui/ui.magnifier.js @@ -1,74 +1,152 @@ +/* + * jQuery UI Magnifier + * + * Copyright (c) 2008 jQuery + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * http://docs.jquery.com/UI/Magnifier + * + * Depends: + * ui.core.js + */ (function($) { - $.widget("ui.magnifier", { - init: function() { +$.widget("ui.magnifier", { + init: function() { - var self = this, o = this.options; - this.items = []; - this.element.addClass("ui-magnifier"); - if(!(/^(r|a)/).test(this.element.css("position"))) this.element.css("position", "relative"); - - this.pp = this.element.offset(); - - $(o.items, this.element).each(function() { + var self = this, o = this.options; + this.items = []; + this.element.addClass("ui-magnifier"); + if(!(/^(r|a)/).test(this.element.css("position"))) this.element.css("position", "relative"); + + this.pp = this.element.offset(); + + $(o.items, this.element).each(function() { - self.items.push([ - this, - $(this).offset(), - [$(this).width(),$(this).height()], - (o.overlap ? $(this).position() : null) - ]); + self.items.push([ + this, + $(this).offset(), + [$(this).width(),$(this).height()], + (o.overlap ? $(this).position() : null) + ]); - if(o.opacity) - $(this).css('opacity', o.opacity.min); + if(o.opacity) + $(this).css('opacity', o.opacity.min); + }); + + if(o.overlap) { + for(var i=0;i this.pp.left-o.distance && p[0] < this.pp.left + this.element[0].offsetWidth + o.distance) && (p[1] > this.pp.top-o.distance && p[1] < this.pp.top + this.element[0].offsetHeight + o.distance)); + if(!overlap) return false; - var o = this.options, c, distance = 1; + for(var i=0;i this.pp.left-o.distance && p[0] < this.pp.left + this.element[0].offsetWidth + o.distance) && (p[1] > this.pp.top-o.distance && p[1] < this.pp.top + this.element[0].offsetHeight + o.distance)); - if(!overlap) return false; - - for(var i=0;i *" - } - }); +}); + +$.extend($.ui.magnifier, { + counter: 0, + defaults: { + distance: 150, + magnification: 2, + baseline: 0, + verticalLine: -0.5, + items: "> *" + } +}); })(jQuery); diff --git a/ui/ui.progressbar.js b/ui/ui.progressbar.js index 55f26cba9..124cb6f44 100644 --- a/ui/ui.progressbar.js +++ b/ui/ui.progressbar.js @@ -8,188 +8,186 @@ * http://docs.jquery.com/UI/ProgressBar * * Depends: - * ui.base.js - * - * Revision: $Id: ui.progressbar.js 5196 2008-04-04 12:52:32Z braeker $ + * ui.core.js */ -;(function($) { +(function($) { - $.widget("ui.progressbar", { - init: function() { +$.widget("ui.progressbar", { + init: function() { - var self = this, o = this.options, text = o.text ? o.text : (o.range ? '0%' : '');; - this.element.addClass("ui-progressbar"); + var self = this, o = this.options, text = o.text ? o.text : (o.range ? '0%' : '');; + this.element.addClass("ui-progressbar"); - $.extend(o, { - stepping: o.stepping > 100 ? 100 : o.stepping - }); - - $.extend(this, { - _step: 0, - rangeValue: 0, - threads: {}, - - wrapper: $("
"), - bar: $("
").css({ - width: '0px', overflow: 'hidden', zIndex: 100 - }), - textElement: $("
").html(text).css({ - width: '0px', overflow: 'hidden' - }), - textBg: $("
").html(text).css({ - width: this.element.css('width') - }) - - }); - - this.wrapper - .append(this.bar.append(this.textElement), this.textBg) - .appendTo(this.element); + $.extend(o, { + stepping: o.stepping > 100 ? 100 : o.stepping + }); + + $.extend(this, { + _step: 0, + rangeValue: 0, + threads: {}, + + wrapper: $("
"), + bar: $("
").css({ + width: '0px', overflow: 'hidden', zIndex: 100 + }), + textElement: $("
").html(text).css({ + width: '0px', overflow: 'hidden' + }), + textBg: $("
").html(text).css({ + width: this.element.css('width') + }) + + }); + + this.wrapper + .append(this.bar.append(this.textElement), this.textBg) + .appendTo(this.element); - }, - - plugins: {}, - ui: function(e) { - return { - instance: this, - options: this.options, - step: this._step, - rangeValue: this.rangeValue, - pixelRange: this.pixelRange - }; - }, - propagate: function(n,e) { - $.ui.plugin.call(this, n, [e, this.ui()]); - this.element.triggerHandler(n == "progressbar" ? n : ["progressbar", n].join(""), [e, this.ui()], this.options[n]); - }, - destroy: function() { - this.reset(); - - this.element - .removeClass("ui-progressbar ui-progressbar-disabled") - .removeData("progressbar").unbind(".progressbar") - .find('.ui-progressbar-wrap').remove(); - }, - enable: function() { - this.element.removeClass("ui-progressbar-disabled"); - this.disabled = false; - if(this.inProgress) this.start(); - }, - disable: function() { - this.element.addClass("ui-progressbar-disabled"); - this.disabled = true; - this.clearThreads(); - }, - start: function() { - - if (this.disabled) return false; - this.inProgress = true; - - var self = this, o = this.options, el = this.element; - this.clearThreads(); - - if (typeof o.wait == 'number' && !self.waitThread) - self.waitThread = setTimeout(function() { - clearInterval(self.waitThread); - self.waitThread = null; - }, o.wait); - - var frames = Math.ceil(100/o.stepping) || 0, ms = o.duration/frames || 0, + }, + + plugins: {}, + ui: function(e) { + return { + instance: this, + options: this.options, + step: this._step, + rangeValue: this.rangeValue, + pixelRange: this.pixelRange + }; + }, + propagate: function(n,e) { + $.ui.plugin.call(this, n, [e, this.ui()]); + this.element.triggerHandler(n == "progressbar" ? n : ["progressbar", n].join(""), [e, this.ui()], this.options[n]); + }, + destroy: function() { + this.reset(); + + this.element + .removeClass("ui-progressbar ui-progressbar-disabled") + .removeData("progressbar").unbind(".progressbar") + .find('.ui-progressbar-wrap').remove(); + }, + enable: function() { + this.element.removeClass("ui-progressbar-disabled"); + this.disabled = false; + if(this.inProgress) this.start(); + }, + disable: function() { + this.element.addClass("ui-progressbar-disabled"); + this.disabled = true; + this.clearThreads(); + }, + start: function() { + + if (this.disabled) return false; + this.inProgress = true; + + var self = this, o = this.options, el = this.element; + this.clearThreads(); + + if (typeof o.wait == 'number' && !self.waitThread) + self.waitThread = setTimeout(function() { + clearInterval(self.waitThread); + self.waitThread = null; + }, o.wait); + + var frames = Math.ceil(100/o.stepping) || 0, ms = o.duration/frames || 0, + + render = function(step, t) { + //clearInterval(t); - render = function(step, t) { - //clearInterval(t); - - self.progress(o.stepping * step); - // on end - if (step >= frames) { - self.stop(); + self.progress(o.stepping * step); + // on end + if (step >= frames) { + self.stop(); - if (self.waitThread || o.wait == 'loop') { - self._step = 0; - self.start(); - } + if (self.waitThread || o.wait == 'loop') { + self._step = 0; + self.start(); } - }; - var from = this._step, _step = (this._step - (from - 1)); - - /*for(var step = from; step <= frames; step++) { - var interval = (step - (from - 1)) * ms; - this.threads[step] = setTimeout(render(step, this.threads[step]), interval); - }*/ - - this.threads[0] = setInterval(function() { - render(_step++); - }, ms); - - this.propagate('start'); - return false; - }, - clearThreads: function() { - $.each(this.threads, function(s, t) { clearInterval(t); }); - this.threads = {}; - }, - stop: function() { - - if (this.disabled) return false; - var o = this.options, self = this; - - this.clearThreads(); - this.propagate('stop'); - - this.inProgress = false; - return false; - - }, - reset: function() { - - if (this.disabled) return false; - this._step = 0; - this.rangeValue = 0; - this.inProgress = false; - this.clearThreads(); - this.progress(0); - this.bar.addClass('ui-hidden'); - return false; - - }, - progress: function(range) { - - var o = this.options, el = this.element, bar = this.bar; - if (this.disabled) return false; - - range = parseInt(range, 10); - this.rangeValue = this._fixRange(range); - this.pixelRange = Math.round( ((this.rangeValue/100)||0) * (el.innerWidth() - (el.outerWidth() - el.innerWidth()) - (bar.outerWidth() - bar.innerWidth())) ); - - this.bar.removeClass('ui-hidden'); - - var css = { width: this.pixelRange + 'px' }; - this.bar.css(css); - this.textElement.css(css); - - if (!o.text && o.range) this.text(this.rangeValue + '%'); - this.propagate('progress', this.rangeValue); - return false; - }, - text: function(text) { - this.textElement.html(text); - }, - _fixRange: function(range) { - var o = this.options; - this._step = Math.ceil(range/o.stepping); - this.rangeValue = Math.round(o.stepping * this._step); - this.rangeValue = (this.rangeValue) >= 100 ? 100 : this.rangeValue; - return this.rangeValue; - } - }); - - $.ui.progressbar.defaults = { - duration: 3000, - stepping: 1, - text: '', - range: true, - addClass: '', - textClass: '' - }; + } + }; + var from = this._step, _step = (this._step - (from - 1)); + + /*for(var step = from; step <= frames; step++) { + var interval = (step - (from - 1)) * ms; + this.threads[step] = setTimeout(render(step, this.threads[step]), interval); + }*/ + + this.threads[0] = setInterval(function() { + render(_step++); + }, ms); + + this.propagate('start'); + return false; + }, + clearThreads: function() { + $.each(this.threads, function(s, t) { clearInterval(t); }); + this.threads = {}; + }, + stop: function() { + + if (this.disabled) return false; + var o = this.options, self = this; + + this.clearThreads(); + this.propagate('stop'); + + this.inProgress = false; + return false; + + }, + reset: function() { + + if (this.disabled) return false; + this._step = 0; + this.rangeValue = 0; + this.inProgress = false; + this.clearThreads(); + this.progress(0); + this.bar.addClass('ui-hidden'); + return false; + + }, + progress: function(range) { + + var o = this.options, el = this.element, bar = this.bar; + if (this.disabled) return false; + + range = parseInt(range, 10); + this.rangeValue = this._fixRange(range); + this.pixelRange = Math.round( ((this.rangeValue/100)||0) * (el.innerWidth() - (el.outerWidth() - el.innerWidth()) - (bar.outerWidth() - bar.innerWidth())) ); + + this.bar.removeClass('ui-hidden'); + + var css = { width: this.pixelRange + 'px' }; + this.bar.css(css); + this.textElement.css(css); + + if (!o.text && o.range) this.text(this.rangeValue + '%'); + this.propagate('progress', this.rangeValue); + return false; + }, + text: function(text) { + this.textElement.html(text); + }, + _fixRange: function(range) { + var o = this.options; + this._step = Math.ceil(range/o.stepping); + this.rangeValue = Math.round(o.stepping * this._step); + this.rangeValue = (this.rangeValue) >= 100 ? 100 : this.rangeValue; + return this.rangeValue; + } +}); + +$.ui.progressbar.defaults = { + duration: 3000, + stepping: 1, + text: '', + range: true, + addClass: '', + textClass: '' +}; })(jQuery); 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("
") - .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('
') - .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('
') - .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("
") + .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('
') + .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('
') + .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); -- cgit v1.2.3