wmdeit_kaform/addons/check/kube.check.min.js

1 line
1.3 KiB
JavaScript
Raw Permalink Normal View History

2020-02-20 13:45:47 +00:00
!function(t){t.add("module","check",{init:function(t,e){this.app=t;var c={target:!1,classname:"ch"};this.context=e,this.params=e.getParams(c),this.$element=e.getElement(),this.$target=e.getTarget()},onclick:function(t,e,c){"all"===c&&this._toggleAll()},start:function(){this.$checkall=this.$element.find("[data-type=all]"),this.$checkboxes=this.$element.find("."+this.params.classname),this.$checkboxes.on("click.kube.check",this._toggle.bind(this)),this._buildChecked()},stop:function(){this.$checkboxes.off(".kube.check"),this.$target.val("")},_buildChecked:function(){if(this.params.target){var t=this.$target.val().split(",");this.$checkboxes.each(function(e){-1!==t.indexOf(e.value)&&(e.checked=!0)}),this.$checkall.attr("checked",this._isCheckedAll())}},_setTarget:function(){if(this.params.target){var t=[];this.$checkboxes.each(function(e){e.checked&&t.push(e.value)});var e=0===t.length?"":t.join(",");this.$target.val(e),this.app.broadcast("check.set",this,this.$target)}},_isCheckedAll:function(){var t=0,e=this.$checkboxes.length;return this.$checkboxes.each(function(e){e.checked&&t++}),e===t},_toggleAll:function(t){var e=this.$checkall.attr("checked");this.$checkboxes.attr("checked",e),this._setTarget()},_toggle:function(){this.$checkall.attr("checked",this._isCheckedAll()),this._setTarget()}})}(Kube);