天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

8 lines
3.5 KiB

/*
* Fuel UX Spinner
* https://github.com/ExactTarget/fuelux
*
* Copyright (c) 2012 ExactTarget
* Licensed under the MIT license.
*/
(function(c,d){var a=c.fn.spinner;var b=function(f,e){this.$element=c(f);this.options=c.extend({},c.fn.spinner.defaults,e);this.$input=this.$element.find(".spinner-input");this.$element.on("keyup",this.$input,c.proxy(this.change,this));if(this.options.hold){this.$element.on("mousedown",".spinner-up",c.proxy(function(){this.startSpin(true)},this));this.$element.on("mouseup",".spinner-up, .spinner-down",c.proxy(this.stopSpin,this));this.$element.on("mouseout",".spinner-up, .spinner-down",c.proxy(this.stopSpin,this));this.$element.on("mousedown",".spinner-down",c.proxy(function(){this.startSpin(false)},this))}else{this.$element.on("click",".spinner-up",c.proxy(function(){this.step(true)},this));this.$element.on("click",".spinner-down",c.proxy(function(){this.step(false)},this))}this.switches={count:1,enabled:true};if(this.options.speed==="medium"){this.switches.speed=300}else{if(this.options.speed==="fast"){this.switches.speed=100}else{this.switches.speed=500}}this.lastValue=null;this.render();if(this.options.disabled){this.disable()}};b.prototype={constructor:b,render:function(){var e=this.$input.val();if(e){this.value(e)}else{this.$input.val(this.options.value)}this.$input.attr("maxlength",(this.options.max+"").split("").length)},change:function(){var e=this.$input.val();if(e/1){this.options.value=e/1}else{e=e.replace(/[^0-9]/g,"")||"";this.$input.val(e);this.options.value=e/1}this.triggerChangedEvent()},stopSpin:function(){if(this.switches.timeout!==d){clearTimeout(this.switches.timeout);this.switches.count=1;this.triggerChangedEvent()}},triggerChangedEvent:function(){var e=this.value();if(e===this.lastValue){return}this.lastValue=e;this.$element.trigger("changed",e);this.$element.trigger("change")},startSpin:function(e){if(!this.options.disabled){var f=this.switches.count;if(f===1){this.step(e);f=1}else{if(f<3){f=1.5}else{if(f<8){f=2.5}else{f=4}}}this.switches.timeout=setTimeout(c.proxy(function(){this.iterator(e)},this),this.switches.speed/f);this.switches.count++}},iterator:function(e){this.step(e);this.startSpin(e)},step:function(g){var k=this.options.value;var j=g?this.options.max:this.options.min;var i,e;if((g?k<j:k>j)){var f=k+(g?1:-1)*this.options.step;if(this.options.step%1!==0){i=(this.options.step+"").split(".")[1].length;e=Math.pow(10,i);f=Math.round(f*e)/e}if(g?f>j:f<j){this.value(j)}else{this.value(f)}}else{if(this.options.cycle){var h=g?this.options.min:this.options.max;this.value(h)}}},value:function(e){if(!isNaN(parseFloat(e))&&isFinite(e)){e=parseFloat(e);this.options.value=e;this.$input.val(e);return this}else{return this.options.value}},disable:function(){this.options.disabled=true;this.$input.attr("disabled","");this.$element.find("button").addClass("disabled")},enable:function(){this.options.disabled=false;this.$input.removeAttr("disabled");this.$element.find("button").removeClass("disabled")}};c.fn.spinner=function(g){var f=Array.prototype.slice.call(arguments,1);var h;var e=this.each(function(){var k=c(this);var j=k.data("spinner");var i=typeof g==="object"&&g;if(!j){k.data("spinner",(j=new b(this,i)))}if(typeof g==="string"){h=j[g].apply(j,f)}});return(h===d)?e:h};c.fn.spinner.defaults={value:1,min:1,max:999,step:1,hold:true,speed:"medium",disabled:false};c.fn.spinner.Constructor=b;c.fn.spinner.noConflict=function(){c.fn.spinner=a;return this};c(function(){c("body").on("mousedown.spinner.data-api",".spinner",function(){var e=c(this);if(e.data("spinner")){return}e.spinner(e.data())})})})(window.jQuery);