primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://gitter.im/primefaces/primeng?ut
123 lines • 5.31 kB
JavaScript
;
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");
var domhandler_1 = require("../dom/domhandler");
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) {
this.toggle(event);
cb.focus();
};
InputSwitch.prototype.onInputChange = function (event) {
var inputChecked = event.target.checked;
this.updateModel(event, inputChecked);
};
InputSwitch.prototype.toggle = function (event) {
if (!this.disabled) {
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.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-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, domhandler_1.DomHandler]
}),
__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