| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- "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 <div [ngClass]=\"{'ui-inputswitch ui-widget': true, 'ui-inputswitch-checked': checked, 'ui-state-disabled': disabled, 'ui-inputswitch-readonly': readonly, 'ui-inputswitch-focus': focused}\" \n [ngStyle]=\"style\" [class]=\"styleClass\" (click)=\"onClick($event, cb)\" role=\"checkbox\" [attr.aria-checked]=\"checked\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #cb type=\"checkbox\" [attr.id]=\"inputId\" [attr.name]=\"name\" [attr.tabindex]=\"tabindex\" [checked]=\"checked\" (change)=\"onInputChange($event)\"\n (focus)=\"onFocus($event)\" (blur)=\"onBlur($event)\" [disabled]=\"disabled\" />\n </div>\n <span class=\"ui-inputswitch-slider\"></span>\n </div>\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
|