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.

0 lines
1.2 KiB

4 years ago
  1. !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);