UNPKG

ng-checkall

Version:

A simple directive to "Check All" checkboxes behavior

3 lines (2 loc) 4.19 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/forms"],t):t(e["ng-checkall"]={},e.ng.core,e.ng.forms)}(this,function(e,o,t){"use strict";var n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};function i(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var r=function(){function e(e){var t=this;this._model=e,this.ngModelChange=new o.EventEmitter,this.registered=!1,this.lockFn=function(){return!1},this.isRegistered=function(){return t.registered}}return e.prototype.registerLockFn=function(e){this.registered=!0,this.lockFn=e},e.prototype._onModelChange=function(e){this.lockFn()||this._model.disabled||this.checkedEmitter.emit(e)},e.prototype.setValue=function(e,t){void 0===t&&(t=!0),t&&!this._model.disabled&&(this.ngModelChange.emit(e),this._model.valueAccessor.writeValue(e))},e}();r.propDecorators={ngModelChange:[{type:o.Output}]};var c=function(r){function e(e){var t=r.call(this,e)||this;return t.model=e,t.checkedAll=new o.EventEmitter,t.onModelChange=t._onModelChange,t.checkedEmitter=t.checkedAll,t}return i(e,r),e}(r);c.decorators=[{type:o.Directive,args:[{selector:"[checkAll]"}]}],c.ctorParameters=function(){return[{type:t.NgModel}]},c.propDecorators={checkedAll:[{type:o.Output}],onModelChange:[{type:o.HostListener,args:["ngModelChange",["$event"]]}]};var s=function(r){function e(e){var t=r.call(this,e)||this;return t.model=e,t.checkedOne=new o.EventEmitter,t.checkedEmitter=t.checkedOne,t}return i(e,r),Object.defineProperty(e.prototype,"disabled",{set:function(e){this._onModelChange.bind(this)(!0)},enumerable:!0,configurable:!0}),e.prototype.ngAfterViewInit=function(){this.model.valueChanges.subscribe(this._onModelChange.bind(this))},e.prototype.getValue=function(){return this.model.value},e.prototype.isDisabled=function(){return this.model.disabled},e}(r);s.decorators=[{type:o.Directive,args:[{selector:"[checkOne]"}]}],s.ctorParameters=function(){return[{type:t.NgModel}]},s.propDecorators={disabled:[{type:o.Input,args:["disabled"]}],checkedOne:[{type:o.Output}]};var u=function(){function e(){this.subscribes=[],this.lock=!1}return e.prototype.process=function(e,t){var r=this,o=function(e){e.isRegistered()||(e.registerLockFn(r.getLock.bind(r)),r.subscribes.push(e.checkedEmitter.subscribe(t)))};e.forEach(o),this.subscribes.push(e.changes.subscribe(function(e){return e.forEach(o)}))},e.prototype.ngAfterViewInit=function(){this.process(this.checkOneDirectives,this.onCheckOne.bind(this)),this.process(this.checkAllDirectives,this.onCheckAll.bind(this))},e.prototype.ngOnDestroy=function(){this.subscribes.forEach(function(e){return e.unsubscribe()})},e.prototype.getCheckboxesToCheck=function(){return this.checkOneDirectives.filter(function(e){return!e.isDisabled()})},e.prototype.getLock=function(){return this.lock},e.prototype.onCheckOne=function(e){var t=this;this.lock=!0,e?setTimeout(this.updateView.bind(this),1):(this.checkAllDirectives.forEach(function(e){return e.setValue(!1,t.lock)}),this.lock=!1)},e.prototype.onCheckAll=function(t){var r=this;this.lock=!0,this.getCheckboxesToCheck().forEach(function(e){return e.setValue(t,r.lock)}),this.lock=!1},e.prototype.updateView=function(){var t=this,r=this.getCheckboxesToCheck().map(function(e){return e.getValue()}).every(function(e){return e});this.checkAllDirectives.forEach(function(e){return e.setValue(r,t.lock)}),this.lock=!1},e}();u.decorators=[{type:o.Directive,args:[{selector:"[checkContainer]"}]}],u.ctorParameters=function(){return[]},u.propDecorators={checkAllDirectives:[{type:o.ContentChildren,args:[c]}],checkOneDirectives:[{type:o.ContentChildren,args:[s]}]};var h=function(){};h.decorators=[{type:o.NgModule,args:[{declarations:[c,u,s],exports:[c,u,s]}]}],h.ctorParameters=function(){return[]},e.NgCheckallModule=h,e.ɵb=r,e.ɵa=c,e.ɵc=u,e.ɵd=s,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ng-checkall.umd.min.js.map