1;(function ($, window){ 2"use strict"; 3var options={ 4customClass: "", 5labels: { 6up: "Up", 7down: "Down" 8}}; 9var pub={ 10defaults: function(opts){ 11options=$.extend(options, opts||{}); 12return (typeof this==='object') ? $(this):true; 13}, 14destroy: function(){ 15return $(this).each(function(i){ 16var data=$(this).data("stepper"); 17if(data){ 18data.$stepper.off(".stepper") 19.find(".stepper-arrow") 20.remove(); 21data.$input.unwrap() 22.removeClass("stepper-input"); 23}}); 24}, 25disable: function(){ 26return $(this).each(function(i){ 27var data=$(this).data("stepper"); 28if(data){ 29data.$input.attr("disabled", "disabled"); 30data.$stepper.addClass("disabled"); 31}}); 32}, 33enable: function(){ 34return $(this).each(function(i){ 35var data=$(this).data("stepper"); 36if(data){ 37data.$input.attr("disabled", null); 38data.$stepper.removeClass("disabled"); 39}}); 40}}; 41function _init(opts){ 42opts=$.extend({}, options, opts||{}); 43var $items=$(this); 44for (var i=0, count=$items.length; i < count; i++){ 45_build($items.eq(i), opts); 46} 47return $items; 48} 49function _build($input, opts){ 50if(!$input.hasClass("stepper-input")){ 51opts=$.extend({}, opts, $input.data("stepper-options")); 52var min=parseFloat($input.attr("min")), 53max=parseFloat($input.attr("max")), 54step=parseFloat($input.attr("step"))||1; 55$input.addClass("stepper-input") 56.wrap('<div class="stepper ' + opts.customClass + '" />') 57.after('<span class="stepper-arrow up">' + opts.labels.up + '</span><span class="stepper-arrow down">' + opts.labels.down + '</span>'); 58var $stepper=$input.parent(".stepper"), 59data=$.extend({ 60$stepper: $stepper, 61$input: $input, 62$arrow: $stepper.find(".stepper-arrow"), 63min: (typeof min!==undefined&&!isNaN(min)) ? min:false, 64max: (typeof max!==undefined&&!isNaN(max)) ? max:false, 65step: (typeof step!==undefined&&!isNaN(step)) ? step:1, 66timer: null 67}, opts); 68data.digits=_digits(data.step); 69if($input.is(":disabled")){ 70$stepper.addClass("disabled"); 71} 72$stepper.on("keypress", ".stepper-input", data, _onKeyup); 73$stepper.on("touchstart.stepper mousedown.stepper", ".stepper-arrow", data, _onMouseDown) 74.data("stepper", data); 75}} 76function _onKeyup(e){ 77var data=e.data; 78if(e.keyCode===38||e.keyCode===40){ 79e.preventDefault(); 80_step(data, (e.keyCode===38) ? data.step:-data.step); 81}} 82function _onMouseDown(e){ 83e.preventDefault(); 84e.stopPropagation(); 85_onMouseUp(e); 86var data=e.data; 87if(!data.$input.is(':disabled')&&!data.$stepper.hasClass("disabled")){ 88var change=$(e.target).hasClass("up") ? data.step:-data.step; 89data.timer=_startTimer(data.timer, 125, function(){ 90_step(data, change, false); 91}); 92_step(data, change); 93$("body").on("touchend.stepper mouseup.stepper", data, _onMouseUp); 94}} 95function _onMouseUp(e){ 96e.preventDefault(); 97e.stopPropagation(); 98var data=e.data; 99_clearTimer(data.timer); 100$("body").off(".stepper"); 101} 102function _step(data, change){ 103var originalValue=parseFloat(data.$input.val()), 104value=change; 105if(typeof originalValue===undefined||isNaN(originalValue)){ 106if(data.min!==false){ 107value=data.min; 108}else{ 109value=0; 110}}else if(data.min!==false&&originalValue < data.min){ 111value=data.min; 112}else{ 113value +=originalValue; 114} 115var diff=(value - data.min) % data.step; 116if(diff!==0){ 117value -=diff; 118} 119if(data.min!==false&&value < data.min){ 120value=data.min; 121} 122if(data.max!==false&&value > data.max){ 123value -=data.step; 124} 125if(value!==originalValue){ 126value=_round(value, data.digits); 127data.$input.val(value) 128.trigger("change"); 129}} 130function _startTimer(timer, time, callback){ 131_clearTimer(timer); 132return setInterval(callback, time); 133} 134function _clearTimer(timer){ 135if(timer){ 136clearInterval(timer); 137timer=null; 138}} 139function _digits(value){ 140var test=String(value); 141if(test.indexOf(".") > -1){ 142return test.length - test.indexOf(".") - 1; 143}else{ 144return 0; 145}} 146function _round(value, digits){ 147var exp=Math.pow(10, digits); 148return Math.round(value * exp) / exp; 149} 150$.fn.stepper=function(method){ 151if(pub[method]){ 152return pub[method].apply(this, Array.prototype.slice.call(arguments, 1)); 153}else if(typeof method==='object'||!method){ 154return _init.apply(this, arguments); 155} 156return this; 157}; 158$.stepper=function(method){ 159if(method==="defaults"){ 160pub.defaults.apply(this, Array.prototype.slice.call(arguments, 1)); 161}};})(jQuery, this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.