"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var common_1 = require("@angular/common"); var forms_1 = require("@angular/forms"); exports.INPUTSWITCH_VALUE_ACCESSOR = { provide: forms_1.NG_VALUE_ACCESSOR, useExisting: core_1.forwardRef(function () { return InputSwitch; }), multi: true }; var InputSwitch = /** @class */ (function () { function InputSwitch(cd) { this.cd = cd; this.onChange = new core_1.EventEmitter(); this.checked = false; this.focused = false; this.onModelChange = function () { }; this.onModelTouched = function () { }; } InputSwitch.prototype.onClick = function (event, cb) { if (!this.disabled && !this.readonly) { this.toggle(event); cb.focus(); } }; InputSwitch.prototype.onInputChange = function (event) { if (!this.readonly) { var inputChecked = event.target.checked; this.updateModel(event, inputChecked); } }; InputSwitch.prototype.toggle = function (event) { this.updateModel(event, !this.checked); }; InputSwitch.prototype.updateModel = function (event, value) { this.checked = value; this.onModelChange(this.checked); this.onChange.emit({ originalEvent: event, checked: this.checked }); }; InputSwitch.prototype.onFocus = function (event) { this.focused = true; }; InputSwitch.prototype.onBlur = function (event) { this.focused = false; this.onModelTouched(); }; InputSwitch.prototype.writeValue = function (checked) { this.checked = checked; this.cd.markForCheck(); }; InputSwitch.prototype.registerOnChange = function (fn) { this.onModelChange = fn; }; InputSwitch.prototype.registerOnTouched = function (fn) { this.onModelTouched = fn; }; InputSwitch.prototype.setDisabledState = function (val) { this.disabled = val; }; __decorate([ core_1.Input(), __metadata("design:type", Object) ], InputSwitch.prototype, "style", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], InputSwitch.prototype, "styleClass", void 0); __decorate([ core_1.Input(), __metadata("design:type", Number) ], InputSwitch.prototype, "tabindex", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], InputSwitch.prototype, "inputId", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], InputSwitch.prototype, "name", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], InputSwitch.prototype, "disabled", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], InputSwitch.prototype, "readonly", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], InputSwitch.prototype, "onChange", void 0); InputSwitch = __decorate([ core_1.Component({ selector: 'p-inputSwitch', template: "\n
\n
\n \n
\n \n
\n ", providers: [exports.INPUTSWITCH_VALUE_ACCESSOR] }), __metadata("design:paramtypes", [core_1.ChangeDetectorRef]) ], InputSwitch); return InputSwitch; }()); exports.InputSwitch = InputSwitch; var InputSwitchModule = /** @class */ (function () { function InputSwitchModule() { } InputSwitchModule = __decorate([ core_1.NgModule({ imports: [common_1.CommonModule], exports: [InputSwitch], declarations: [InputSwitch] }) ], InputSwitchModule); return InputSwitchModule; }()); exports.InputSwitchModule = InputSwitchModule; //# sourceMappingURL=inputswitch.js.map