UNPKG

jw-bootstrap-switch-ng2

Version:
2 lines 10.9 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define("jw-bootstrap-switch-ng2",["exports","@angular/core","@angular/forms","@angular/common"],t):t(e["jw-bootstrap-switch-ng2"]={},e.ng.core,e.ng.forms,e.ng.common)}(this,function(e,n,t,s){"use strict";var i=function(){},o={provide:t.NG_VALUE_ACCESSOR,useExisting:n.forwardRef(function(){return a}),multi:!0},a=function(){function e(e,t){this.cd=e,this.render=t,this.handleWidth=0,this.labelWidth=0,this.labelText="",this.inverse=!1,this.baseClass="bootstrap-switch",this.onText="ON",this.offText="OFF",this.disabled=!1,this.readonly=!1,this._focused=!1,this._size="normal",this._animate=!0,this._innerAnimate=!0,this._indeterminate=!1,this._onColor="primary",this._offColor="default",this._wrapperClass="wrapper",this._innerState=!1,this._innerHandleWidth="auto",this._innerLabelWidth="auto",this._dragStart=null,this._dragEnd=null,this._onTouchedCallback=i,this._onChangeCallback=i,this.changeState=new n.EventEmitter}return e.prototype.$on=function(){return this.on.nativeElement},e.prototype.$off=function(){return this.off.nativeElement},e.prototype.$label=function(){return this.label.nativeElement},e.prototype.$container=function(){return this.container.nativeElement},e.prototype.getWrapperClasses=function(){var e=this.baseClass+" "+this.baseClass+"-"+this._wrapperClass;return this._focused&&(e+=" "+this.baseClass+"-focused"),this.readonly&&(e+=" "+this.baseClass+"-readonly"),null!=this._size&&(e+=" "+this.baseClass+"-"+this._size),this._innerState?e+=" "+this.baseClass+"-on":e+=" "+this.baseClass+"-off",this._animate&&(e+=" "+this.baseClass+"-animate"),this.disabled&&(e+=" "+this.baseClass+"-disabled"),(this._indeterminate||null===this._innerState||"undefined"==typeof this._innerState)&&(e+=" "+this.baseClass+"-indeterminate"),this.inverse&&(e+=" "+this.baseClass+"-inverse"),e},e.prototype.getOnClasses=function(){var e=this.baseClass+"-handle-on";return this._onColor&&(e+=" "+this.baseClass+"-"+this._onColor),e},e.prototype.getOffClasses=function(){var e=this.baseClass+"-handle-off";return this._offColor&&(e+=" "+this.baseClass+"-"+this._offColor),e},e.prototype.getLabelMarginLeft=function(){var e=this.inverse?-this.handleWidth:0;return this._indeterminate||null===this._innerState||"undefined"==typeof this._innerState?e=-this.handleWidth/2:this._dragEnd?e=this._dragEnd:this._innerState||(e=this.inverse?0:-this.handleWidth),e+"px"},e.prototype.ngOnChanges=function(e){(e.setLabelText||e.setOnText||e.setHandleWidth||e.setLabelWidth||e.setOffText||e.setSize)&&this.calculateWith(!0)},e.prototype.ngAfterViewInit=function(){this.calculateWith()},e.prototype.onClick=function(){this.disabled||this.readonly||this._dragEnd?this._dragEnd&&(this._dragEnd=null):this.setStateValue(!this._innerState)},e.prototype.onKeyDown=function(e){if(e.which&&!this.disabled&&!this.readonly)switch(e.which){case 37:e.preventDefault(),e.stopImmediatePropagation(),this.setStateValue(!1);break;case 39:e.preventDefault(),e.stopImmediatePropagation(),this.setStateValue(!0)}},e.prototype.onDragStart=function(e){if(e.target===this.$label()){if(this._dragStart||this.disabled||this.readonly)return;e.preventDefault(),e.stopPropagation(),this._dragStart=(e.pageX||e.touches[0].pageX)-parseInt(this.$container().style.marginLeft,10),this._animate&&(this._animate=!this._animate)}},e.prototype.onDragMove=function(e){if(this._dragStart){e.preventDefault();var t=(e.pageX||e.touches[0].pageX)-this._dragStart;if(t<-Number(this.handleWidth)||0<t)return;this._dragEnd=t}},e.prototype.onDragEnd=function(e,t){if(void 0===t&&(t=!1),this._dragStart){if(e.preventDefault(),e.stopPropagation(),this._dragEnd){var n=this._dragEnd>-Number(this.handleWidth)/2;this.setStateValue(this.inverse?!n:n)}this._dragStart=null,t&&(this._dragEnd=null),this._innerAnimate&&(this._animate=!0)}},e.prototype.onTouchStart=function(e){this.onDragStart(e)},e.prototype.onMouseDown=function(e){this.onDragStart(e)},e.prototype.onTouchMove=function(e){this.onDragMove(e)},e.prototype.onMouseMove=function(e){this.onDragMove(e)},e.prototype.onMouseUp=function(e){this.onDragEnd(e)},e.prototype.onTouchEnd=function(e){this.onDragEnd(e,!0)},e.prototype.onMouseLeave=function(e){this.onDragEnd(e,!0)},e.prototype.onFocus=function(){this._focused=!0},e.prototype.onBlur=function(){this._focused=!1,this._onTouchedCallback()},e.prototype.calculateWith=function(t){var n=this;void 0===t&&(t=!1),t&&this._innerAnimate&&(this._animate=!1),setTimeout(function(){n.render.setStyle(n.$on(),"width","auto"),n.render.setStyle(n.$off(),"width","auto"),n.render.setStyle(n.$label(),"width","auto");var e="auto"===n._innerHandleWidth?Math.max(n.$on().offsetWidth,n.$off().offsetWidth):n._innerHandleWidth;n.$label().offsetWidth<e?"auto"===n._innerLabelWidth?n.labelWidth=Number(e):n.labelWidth=Number(n._innerLabelWidth):"auto"===n._innerLabelWidth?n.labelWidth=n.$label().offsetWidth:n.labelWidth=Number(n._innerLabelWidth),n.handleWidth=Number(e),n.render.setStyle(n.$label(),"width",n.labelWidth+"px"),n.render.setStyle(n.$on(),"width",n.handleWidth+"px"),n.render.setStyle(n.$off(),"width",n.handleWidth+"px"),setTimeout(function(){t&&n._innerAnimate&&(n._animate=!0)}),n.cd.markForCheck()})},Object.defineProperty(e.prototype,"setBaseClass",{set:function(e){this.baseClass=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setWrapperClass",{set:function(e){this._wrapperClass=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setOffText",{set:function(e){this.offText=e||"OFF"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setLabelText",{set:function(e){this.labelText=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setOnText",{set:function(e){this.onText=e||"ON"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setSize",{set:function(e){e&&(this._size=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setAnimate",{set:function(e){this._animate=e,this._innerAnimate=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setOnColor",{set:function(e){e&&(this._onColor=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setOffColor",{set:function(e){e&&(this._offColor=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setDisabled",{set:function(e){this.disabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setReadOnly",{set:function(e){this.readonly=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setIndeterminate",{set:function(e){this._indeterminate=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setInverse",{set:function(e){this.inverse=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setHandleWidth",{set:function(e){this._innerHandleWidth=void 0!==e?e:"auto"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"setLabelWidth",{set:function(e){this._innerLabelWidth=void 0!==e?e:"auto"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._innerState},set:function(e){null==e&&(this._indeterminate=!0),this.setStateValue(e)},enumerable:!0,configurable:!0}),e.prototype.setStateValue=function(e){e!==this._innerState&&(this._onChangeCallback(e),this.changeState.emit({previousValue:this._innerState,currentValue:e}),this._innerState=e)},e.prototype.writeValue=function(e){e!==this._innerState&&(this._innerState=e,this.cd.markForCheck())},e.prototype.setDisabledState=function(e){this.disabled=e},e.prototype.registerOnChange=function(e){this._onChangeCallback=e},e.prototype.registerOnTouched=function(e){this._onTouchedCallback=e},e.decorators=[{type:n.Component,args:[{selector:"bSwitch",providers:[o],template:'\n <div [ngClass]="getWrapperClasses()" [style.width]="(handleWidth + labelWidth ) +\'px\'">\n <div #container [ngClass]="baseClass + \'-container\'"\n [style.width]="((handleWidth * 2) + labelWidth) +\'px\'"\n [style.margin-left]="getLabelMarginLeft()">\x3c!--\n --\x3e<span #on [innerHTML]="(inverse) ? offText : onText"\n [ngClass]="(inverse) ? getOffClasses() : getOnClasses()"></span>\x3c!--\n --\x3e<span #label [ngClass]="baseClass + \'-label\'">&nbsp;{{ labelText }}</span>\x3c!--\n --\x3e<span #off [innerHTML]="(inverse) ? onText : offText"\n [ngClass]="(inverse) ? getOnClasses() : getOffClasses()"></span>\x3c!--\n --\x3e<input type="checkbox" [(ngModel)]="value" [readonly]="readonly" [disabled]="disabled"\n (focus)="onFocus()" (blur)="onBlur()">\n </div>\n </div>'}]}],e.ctorParameters=function(){return[{type:n.ChangeDetectorRef},{type:n.Renderer2}]},e.propDecorators={changeState:[{type:n.Output}],container:[{type:n.ViewChild,args:["container"]}],on:[{type:n.ViewChild,args:["on"]}],label:[{type:n.ViewChild,args:["label"]}],off:[{type:n.ViewChild,args:["off"]}],onClick:[{type:n.HostListener,args:["click"]}],onKeyDown:[{type:n.HostListener,args:["keydown",["$event"]]}],onTouchStart:[{type:n.HostListener,args:["touchstart",["$event"]]}],onMouseDown:[{type:n.HostListener,args:["mousedown",["$event"]]}],onTouchMove:[{type:n.HostListener,args:["touchmove",["$event"]]}],onMouseMove:[{type:n.HostListener,args:["mousemove",["$event"]]}],onMouseUp:[{type:n.HostListener,args:["mouseup",["$event"]]}],onTouchEnd:[{type:n.HostListener,args:["touchend",["$event"]]}],onMouseLeave:[{type:n.HostListener,args:["mouseleave",["$event"]]}],setBaseClass:[{type:n.Input,args:["switch-base-class"]}],setWrapperClass:[{type:n.Input,args:["switch-wrapper-class"]}],setOffText:[{type:n.Input,args:["switch-off-text"]}],setLabelText:[{type:n.Input,args:["switch-label-text"]}],setOnText:[{type:n.Input,args:["switch-on-text"]}],setSize:[{type:n.Input,args:["switch-size"]}],setAnimate:[{type:n.Input,args:["switch-animate"]}],setOnColor:[{type:n.Input,args:["switch-on-color"]}],setOffColor:[{type:n.Input,args:["switch-off-color"]}],setDisabled:[{type:n.Input,args:["switch-disabled"]}],setReadOnly:[{type:n.Input,args:["switch-readonly"]}],setIndeterminate:[{type:n.Input,args:["switch-indeterminate"]}],setInverse:[{type:n.Input,args:["switch-inverse"]}],setHandleWidth:[{type:n.Input,args:["switch-handle-width"]}],setLabelWidth:[{type:n.Input,args:["switch-label-width"]}]},e}(),r=function(){function e(){}return e.decorators=[{type:n.NgModule,args:[{imports:[s.CommonModule,t.FormsModule],declarations:[a],exports:[a]}]}],e}();e.JwBootstrapSwitchNg2Component=a,e.JwBootstrapSwitchNg2Module=r,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=jw-bootstrap-switch-ng2.umd.min.js.map