|
- (function(p){var g=!1,k=p.fn.val;p.fn.val=function(o){if(arguments.length>=1&&this[0]&&this[0]["bootstrap-input-spinner"]&&this[0].setValue){var n=this[0];setTimeout(function(){n.setValue(o)})}return k.apply(this,arguments)},p.fn.InputSpinner=p.fn.inputSpinner=function(o){var n={decrementButton:"<strong>-</strong>",incrementButton:"<strong>+</strong>",groupClass:"",buttonsClass:"btn-outline-secondary",buttonsWidth:"2.5rem",textAlign:"center",autoDelay:500,autoInterval:100,boostThreshold:10,boostMultiplier:"auto",locale:null};for(var r in o)n[r]=o[r];var R='<div class="input-group '+n.groupClass+'"><div class="input-group-prepend"><button style="min-width: '+n.buttonsWidth+'" class="btn btn-decrement '+n.buttonsClass+'" type="button">'+n.decrementButton+'</button></div><input type="text" style="text-align: '+n.textAlign+'" class="form-control"/><div class="input-group-append"><button style="min-width: '+n.buttonsWidth+'" class="btn btn-increment '+n.buttonsClass+'" type="button">'+n.incrementButton+"</button></div></div>",D=n.locale||navigator.language||"en-US";return this.each(function(){var e=p(this);e[0]["bootstrap-input-spinner"]=!0,e.hide();var N=null,I=null,b=n.boostMultiplier==="auto",s=b?1:n.boostMultiplier,l=p(R),T=l.find(".btn-decrement"),L=l.find(".btn-increment"),u=l.find("input"),S=null,w=null,h=null,y=null,f=null,x=null,B=null;O();var d=parseFloat(e[0].value),E=0,G=e.attr("data-prefix")||"",A=e.attr("data-suffix")||"";if(G){var U=p('<span class="input-group-text">'+G+"</span>");l.find(".input-group-prepend").append(U)}if(A){var j=p('<span class="input-group-text">'+A+"</span>");l.find(".input-group-append").prepend(j)}e[0].setValue=function(t){c(t)};var K=new MutationObserver(function(){O(),c(d,!0)});K.observe(e[0],{attributes:!0}),e.after(l),c(d),u.on("paste input change focusout",function(t){var a=u[0].value,i=t.type==="focusout";a=Q(a),c(a,i),M(e,t.type)}),F(T[0],function(){H(-h)}),F(L[0],function(){H(h)}),q(document.body,function(){C()});function c(t,a){a===void 0&&(a=!0),isNaN(t)||t===""?(e[0].value="",a&&(u[0].value=""),d=NaN):(t=parseFloat(t),t=Math.min(Math.max(t,S),w),t=Math.round(t*Math.pow(10,f))/Math.pow(10,f),e[0].value=t,a&&(u[0].value=B.format(t)),d=t)}function M(t,a){a&&setTimeout(function(){var i;typeof Event=="function"?i=new Event(a,{bubbles:!0}):(i=document.createEvent("Event"),i.initEvent(a,!0,!0)),t[0].dispatchEvent(i)})}function H(t){!u[0].disabled&&!u[0].readOnly&&(m(t),C(),N=setTimeout(function(){I=setInterval(function(){E>n.boostThreshold?b?(m(t*parseInt(s,10)),s<1e8&&(s=s*1.1),y&&(s=Math.min(y,s))):m(t*s):m(t),E++},n.autoInterval)},n.autoDelay))}function m(t){isNaN(d)&&(d=0),c(Math.round(d/t)*t+t),M(e,"input"),M(e,"change")}function C(){E=0,s=s=b?1:n.boostMultiplier,clearTimeout(N),clearTimeout(I)}function O(){u.prop("required",e.prop("required")),u.prop("placeholder",e.prop("placeholder"));var t=e.prop("disabled"),a=e.prop("readonly");u.prop("disabled",t),u.prop("readonly",a),L.prop("disabled",t||a),T.prop("disabled",t||a),(t||a)&&C();var i=e.prop("class"),v="";/form-control-sm/g.test(i)?v="input-group-sm":/form-control-lg/g.test(i)&&(v="input-group-lg");var z=i.replace(/form-control(-(sm|lg))?/g,"");l.prop("class","input-group "+v+" "+n.groupClass),u.prop("class","form-control "+z),S=parseFloat(e.prop("min"))||0,w=isNaN(e.prop("max"))||e.prop("max")===""?1/0:parseFloat(e.prop("max")),h=parseFloat(e.prop("step"))||1,y=parseInt(e.attr("data-step-max"))||0;var P=parseInt(e.attr("data-decimals"))||0,W=e.attr("data-digit-grouping")!=="false";(f!==P||x!==W)&&(f=P,x=W,B=new Intl.NumberFormat(D,{minimumFractionDigits:f,maximumFractionDigits:f,useGrouping:x}))}function Q(t){var a=new Intl.NumberFormat(D),i=a.format(1111).replace(/1/g,""),v=a.format(1.1).replace(/1/g,"");return parseFloat(t.replace(new RegExp("\\"+i,"g"),"").replace(new RegExp("\\"+v),"."))}}),this};function q(o,n){o.addEventListener("mouseup",function(r){n(r)}),o.addEventListener("touchend",function(r){n(r)}),o.addEventListener("keyup",function(r){(r.keyCode===32||r.keyCode===13)&&(g=!1,n(r))})}function F(o,n){o.addEventListener("mousedown",function(r){r.preventDefault(),n(r)}),o.addEventListener("touchstart",function(r){r.cancelable&&r.preventDefault(),n(r)}),o.addEventListener("keydown",function(r){(r.keyCode===32||r.keyCode===13)&&!g&&(g=!0,n(r))})}})(jQuery);
|