1
0
Fork 0
wmdeit_kaform/addons/number/kube.number.min.js

1 line
1.2 KiB
JavaScript
Raw Permalink Normal View History

2020-02-20 13:45:47 +00:00
!function(t){t.add("module","number",{init:function(t,i){this.app=t,this.context=i,this.$element=i.getElement()},start:function(){this.$input=this.$element.find('input[type="number"]'),this.$btnUp=this.$element.find(".is-up"),this.$btnDown=this.$element.find(".is-down"),this._buildStep(),this._buildMin(),this._buildMax(),this._isDisabled()||(this.$btnUp.on("click.kube.number",this._increase.bind(this)),this.$btnDown.on("click.kube.number",this._decrease.bind(this)))},stop:function(){this.$btnUp.off(".kube.number"),this.$btnDown.off(".kube.number")},_buildStep:function(){var t=this.$input.attr("step");this.step=t?parseFloat(t):1},_buildMin:function(){var t=this.$input.attr("min");this.min=t?parseFloat(t):!1},_buildMax:function(){var t=this.$input.attr("max");this.max=t?parseFloat(t):!1},_isDisabled:function(){return this.$input.attr("disabled")},_getValue:function(){var t=parseFloat(this.$input.val()),i=this.min===!1?0:this.min;return isNaN(t)?i:t},_increase:function(t){t&&(t.preventDefault(),t.stopPropagation());var i=this._getValue(),n=this.max!==!1&&i>=this.max?i:i+this.step;this.$input.val(n)},_decrease:function(t){t&&(t.preventDefault(),t.stopPropagation());var i=this._getValue(),n=this.min!==!1&&i<=this.min?i:i-this.step;this.$input.val(n)}})}(Kube);