tristatecheckbox.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. 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;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var common_1 = require("@angular/common");
  14. var forms_1 = require("@angular/forms");
  15. exports.TRISTATECHECKBOX_VALUE_ACCESSOR = {
  16. provide: forms_1.NG_VALUE_ACCESSOR,
  17. useExisting: core_1.forwardRef(function () { return TriStateCheckbox; }),
  18. multi: true
  19. };
  20. var TriStateCheckbox = /** @class */ (function () {
  21. function TriStateCheckbox(cd) {
  22. this.cd = cd;
  23. this.onChange = new core_1.EventEmitter();
  24. this.onModelChange = function () { };
  25. this.onModelTouched = function () { };
  26. }
  27. TriStateCheckbox.prototype.onClick = function (event, input) {
  28. if (!this.disabled && !this.readonly) {
  29. this.toggle(event);
  30. this.focus = true;
  31. input.focus();
  32. }
  33. };
  34. TriStateCheckbox.prototype.onKeydown = function (event) {
  35. if (event.keyCode == 32) {
  36. event.preventDefault();
  37. }
  38. };
  39. TriStateCheckbox.prototype.onKeyup = function (event) {
  40. if (event.keyCode == 32 && !this.readonly) {
  41. this.toggle(event);
  42. event.preventDefault();
  43. }
  44. };
  45. TriStateCheckbox.prototype.toggle = function (event) {
  46. if (this.value == null || this.value == undefined)
  47. this.value = true;
  48. else if (this.value == true)
  49. this.value = false;
  50. else if (this.value == false)
  51. this.value = null;
  52. this.onModelChange(this.value);
  53. this.onChange.emit({
  54. originalEvent: event,
  55. value: this.value
  56. });
  57. };
  58. TriStateCheckbox.prototype.onFocus = function () {
  59. this.focus = true;
  60. };
  61. TriStateCheckbox.prototype.onBlur = function () {
  62. this.focus = false;
  63. this.onModelTouched();
  64. };
  65. TriStateCheckbox.prototype.registerOnChange = function (fn) {
  66. this.onModelChange = fn;
  67. };
  68. TriStateCheckbox.prototype.registerOnTouched = function (fn) {
  69. this.onModelTouched = fn;
  70. };
  71. TriStateCheckbox.prototype.writeValue = function (value) {
  72. this.value = value;
  73. this.cd.markForCheck();
  74. };
  75. TriStateCheckbox.prototype.setDisabledState = function (disabled) {
  76. this.disabled = disabled;
  77. };
  78. __decorate([
  79. core_1.Input(),
  80. __metadata("design:type", Boolean)
  81. ], TriStateCheckbox.prototype, "disabled", void 0);
  82. __decorate([
  83. core_1.Input(),
  84. __metadata("design:type", String)
  85. ], TriStateCheckbox.prototype, "name", void 0);
  86. __decorate([
  87. core_1.Input(),
  88. __metadata("design:type", Number)
  89. ], TriStateCheckbox.prototype, "tabindex", void 0);
  90. __decorate([
  91. core_1.Input(),
  92. __metadata("design:type", String)
  93. ], TriStateCheckbox.prototype, "inputId", void 0);
  94. __decorate([
  95. core_1.Input(),
  96. __metadata("design:type", Object)
  97. ], TriStateCheckbox.prototype, "style", void 0);
  98. __decorate([
  99. core_1.Input(),
  100. __metadata("design:type", String)
  101. ], TriStateCheckbox.prototype, "styleClass", void 0);
  102. __decorate([
  103. core_1.Input(),
  104. __metadata("design:type", String)
  105. ], TriStateCheckbox.prototype, "label", void 0);
  106. __decorate([
  107. core_1.Input(),
  108. __metadata("design:type", Boolean)
  109. ], TriStateCheckbox.prototype, "readonly", void 0);
  110. __decorate([
  111. core_1.Output(),
  112. __metadata("design:type", core_1.EventEmitter)
  113. ], TriStateCheckbox.prototype, "onChange", void 0);
  114. TriStateCheckbox = __decorate([
  115. core_1.Component({
  116. selector: 'p-triStateCheckbox',
  117. template: "\n <div [ngStyle]=\"style\" [ngClass]=\"{'ui-chkbox ui-tristatechkbox ui-widget': true,'ui-chkbox-readonly': readonly}\" [class]=\"styleClass\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #input type=\"text\" [attr.id]=\"inputId\" [name]=\"name\" [attr.tabindex]=\"tabindex\" [readonly]=\"readonly\" [disabled]=\"disabled\" (keyup)=\"onKeyup($event)\" (keydown)=\"onKeydown($event)\" (focus)=\"onFocus()\" (blur)=\"onBlur()\">\n </div>\n <div class=\"ui-chkbox-box ui-widget ui-corner-all ui-state-default\" (click)=\"onClick($event,input)\"\n [ngClass]=\"{'ui-state-active':value!=null,'ui-state-disabled':disabled,'ui-state-focus':focus}\">\n <span class=\"ui-chkbox-icon pi ui-clickable\" [ngClass]=\"{'pi-check':value==true,'pi-times':value==false}\"></span>\n </div>\n </div>\n <label class=\"ui-chkbox-label\" (click)=\"onClick($event,input)\"\n [ngClass]=\"{'ui-label-active':value!=null, 'ui-label-disabled':disabled, 'ui-label-focus':focus}\"\n *ngIf=\"label\" [attr.for]=\"inputId\">{{label}}</label>\n ",
  118. providers: [exports.TRISTATECHECKBOX_VALUE_ACCESSOR]
  119. }),
  120. __metadata("design:paramtypes", [core_1.ChangeDetectorRef])
  121. ], TriStateCheckbox);
  122. return TriStateCheckbox;
  123. }());
  124. exports.TriStateCheckbox = TriStateCheckbox;
  125. var TriStateCheckboxModule = /** @class */ (function () {
  126. function TriStateCheckboxModule() {
  127. }
  128. TriStateCheckboxModule = __decorate([
  129. core_1.NgModule({
  130. imports: [common_1.CommonModule],
  131. exports: [TriStateCheckbox],
  132. declarations: [TriStateCheckbox]
  133. })
  134. ], TriStateCheckboxModule);
  135. return TriStateCheckboxModule;
  136. }());
  137. exports.TriStateCheckboxModule = TriStateCheckboxModule;
  138. //# sourceMappingURL=tristatecheckbox.js.map