ngx-bootstrap
Version:
Native Angular Bootstrap Components
2 lines • 8.35 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms")):"function"==typeof define&&define.amd?define("ngx-bootstrap/buttons",["exports","@angular/core","@angular/forms"],e):e(((t=t||self)["ngx-bootstrap"]=t["ngx-bootstrap"]||{},t["ngx-bootstrap"].buttons={}),t.ng.core,t.ng.forms)}(this,(function(t,e,o){"use strict";var n={provide:o.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return r})),multi:!0},r=function(){function t(){this.btnCheckboxTrue=!0,this.btnCheckboxFalse=!1,this.state=!1,this.onChange=Function.prototype,this.onTouched=Function.prototype}return t.prototype.onClick=function(){this.isDisabled||(this.toggle(!this.state),this.onChange(this.value))},t.prototype.ngOnInit=function(){this.toggle(this.trueValue===this.value)},Object.defineProperty(t.prototype,"trueValue",{get:function(){return void 0===this.btnCheckboxTrue||this.btnCheckboxTrue},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"falseValue",{get:function(){return void 0!==this.btnCheckboxFalse&&this.btnCheckboxFalse},enumerable:!0,configurable:!0}),t.prototype.toggle=function(t){this.state=t,this.value=this.state?this.trueValue:this.falseValue},t.prototype.writeValue=function(t){this.state=this.trueValue===t,this.value=t?this.trueValue:this.falseValue},t.prototype.setDisabledState=function(t){this.isDisabled=t},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouched=t},t.decorators=[{type:e.Directive,args:[{selector:"[btnCheckbox]",providers:[n]}]}],t.propDecorators={btnCheckboxTrue:[{type:e.Input}],btnCheckboxFalse:[{type:e.Input}],state:[{type:e.HostBinding,args:["class.active"]},{type:e.HostBinding,args:["attr.aria-pressed"]}],onClick:[{type:e.HostListener,args:["click"]}]},t}();var i={provide:o.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return s})),multi:!0},s=function(){function t(t,e,o,n){this.el=t,this.cdr=e,this.renderer=o,this.group=n,this.onChange=Function.prototype,this.onTouched=Function.prototype,this.role="radio",this._hasFocus=!1}return Object.defineProperty(t.prototype,"value",{get:function(){return this.group?this.group.value:this._value},set:function(t){this.group?this.group.value=t:this._value=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"disabled",{get:function(){return this._disabled},set:function(t){this.setDisabledState(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"controlOrGroupDisabled",{get:function(){return!!(this.disabled||this.group&&this.group.disabled)||void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasDisabledClass",{get:function(){return this.controlOrGroupDisabled&&!this.isActive},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isActive",{get:function(){return this.btnRadio===this.value},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tabindex",{get:function(){return this.controlOrGroupDisabled?void 0:this.isActive||null==this.group?0:-1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasFocus",{get:function(){return this._hasFocus},enumerable:!0,configurable:!0}),t.prototype.toggleIfAllowed=function(){this.canToggle()&&(this.value=this.uncheckable&&this.btnRadio===this.value?void 0:this.btnRadio,this._onChange(this.value))},t.prototype.onSpacePressed=function(t){this.toggleIfAllowed(),t.preventDefault()},t.prototype.focus=function(){this.el.nativeElement.focus()},t.prototype.onFocus=function(){this._hasFocus=!0},t.prototype.onBlur=function(){this._hasFocus=!1,this.onTouched()},t.prototype.canToggle=function(){return!this.controlOrGroupDisabled&&(this.uncheckable||this.btnRadio!==this.value)},t.prototype.ngOnInit=function(){this.uncheckable=void 0!==this.uncheckable},t.prototype._onChange=function(t){this.group?this.group.value=t:(this.onTouched(),this.onChange(t))},t.prototype.writeValue=function(t){this.value=t,this.cdr.markForCheck()},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouched=t},t.prototype.setDisabledState=function(t){this._disabled=t,t?this.renderer.setAttribute(this.el.nativeElement,"disabled","disabled"):this.renderer.removeAttribute(this.el.nativeElement,"disabled")},t.decorators=[{type:e.Directive,args:[{selector:"[btnRadio]",providers:[i]}]}],t.ctorParameters=function(){return[{type:e.ElementRef},{type:e.ChangeDetectorRef},{type:e.Renderer2},{type:a,decorators:[{type:e.Optional},{type:e.Inject,args:[e.forwardRef((function(){return a}))]}]}]},t.propDecorators={btnRadio:[{type:e.Input}],uncheckable:[{type:e.Input}],value:[{type:e.Input}],disabled:[{type:e.Input}],controlOrGroupDisabled:[{type:e.HostBinding,args:["attr.aria-disabled"]}],hasDisabledClass:[{type:e.HostBinding,args:["class.disabled"]}],isActive:[{type:e.HostBinding,args:["class.active"]},{type:e.HostBinding,args:["attr.aria-checked"]}],role:[{type:e.HostBinding,args:["attr.role"]}],tabindex:[{type:e.HostBinding,args:["attr.tabindex"]}],toggleIfAllowed:[{type:e.HostListener,args:["click"]}],onSpacePressed:[{type:e.HostListener,args:["keydown.space",["$event"]]}],onFocus:[{type:e.HostListener,args:["focus"]}],onBlur:[{type:e.HostListener,args:["blur"]}]},t}();var u={provide:o.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return a})),multi:!0},a=function(){function t(t){this.cdr=t,this.onChange=Function.prototype,this.onTouched=Function.prototype,this.role="radiogroup"}return Object.defineProperty(t.prototype,"value",{get:function(){return this._value},set:function(t){this._value=t,this.onChange(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tabindex",{get:function(){return this._disabled?null:0},enumerable:!0,configurable:!0}),t.prototype.writeValue=function(t){this._value=t,this.cdr.markForCheck()},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouched=t},t.prototype.setDisabledState=function(t){this.radioButtons&&(this._disabled=t,this.radioButtons.forEach((function(e){e.setDisabledState(t)})),this.cdr.markForCheck())},t.prototype.onFocus=function(){if(!this._disabled){var t=this.getActiveOrFocusedRadio();if(t)t.focus();else{var e=this.radioButtons.find((function(t){return!t.disabled}));e&&e.focus()}}},t.prototype.onBlur=function(){this.onTouched&&this.onTouched()},t.prototype.selectNext=function(t){this.selectInDirection("next"),t.preventDefault()},t.prototype.selectPrevious=function(t){this.selectInDirection("previous"),t.preventDefault()},Object.defineProperty(t.prototype,"disabled",{get:function(){return this._disabled},enumerable:!0,configurable:!0}),t.prototype.selectInDirection=function(t){if(!this._disabled){var e=this.getActiveOrFocusedRadio();if(e)for(var o=this.radioButtons.toArray(),n=o.indexOf(e),r=i(n,o);r!==n;r=i(r,o))if(o[r].canToggle()){o[r].toggleIfAllowed(),o[r].focus();break}}function i(e,o){var n=(e+("next"===t?1:-1))%o.length;return n<0&&(n=o.length-1),n}},t.prototype.getActiveOrFocusedRadio=function(){return this.radioButtons.find((function(t){return t.isActive}))||this.radioButtons.find((function(t){return t.hasFocus}))},t.decorators=[{type:e.Directive,args:[{selector:"[btnRadioGroup]",providers:[u]}]}],t.ctorParameters=function(){return[{type:e.ChangeDetectorRef}]},t.propDecorators={role:[{type:e.HostBinding,args:["attr.role"]}],radioButtons:[{type:e.ContentChildren,args:[e.forwardRef((function(){return s}))]}],tabindex:[{type:e.HostBinding,args:["attr.tabindex"]}],onFocus:[{type:e.HostListener,args:["focus"]}],onBlur:[{type:e.HostListener,args:["blur"]}],selectNext:[{type:e.HostListener,args:["keydown.ArrowRight",["$event"]]},{type:e.HostListener,args:["keydown.ArrowDown",["$event"]]}],selectPrevious:[{type:e.HostListener,args:["keydown.ArrowLeft",["$event"]]},{type:e.HostListener,args:["keydown.ArrowUp",["$event"]]}]},t}();var c=function(){function t(){}return t.forRoot=function(){return{ngModule:t,providers:[]}},t.decorators=[{type:e.NgModule,args:[{declarations:[r,s,a],exports:[r,s,a]}]}],t}();t.ButtonCheckboxDirective=r,t.ButtonRadioDirective=s,t.ButtonRadioGroupDirective=a,t.ButtonsModule=c,t.ɵa=n,t.ɵb=u,t.ɵc=i,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-bootstrap-buttons.umd.min.js.map