1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/forms')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/togglebutton', ['exports', '@angular/core', '@angular/common', '@angular/forms'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.togglebutton = {}), global.ng.core, global.ng.common, global.ng.forms));
|
5 | }(this, (function (exports, core, common, forms) { 'use strict';
|
6 |
|
7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
10 | 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;
|
11 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
12 | };
|
13 | var TOGGLEBUTTON_VALUE_ACCESSOR = {
|
14 | provide: forms.NG_VALUE_ACCESSOR,
|
15 | useExisting: core.forwardRef(function () { return ToggleButton; }),
|
16 | multi: true
|
17 | };
|
18 | var ToggleButton = (function () {
|
19 | function ToggleButton() {
|
20 | this.onLabel = 'Yes';
|
21 | this.offLabel = 'No';
|
22 | this.iconPos = 'left';
|
23 | this.onChange = new core.EventEmitter();
|
24 | this.checked = false;
|
25 | this.focus = false;
|
26 | this.onModelChange = function () { };
|
27 | this.onModelTouched = function () { };
|
28 | }
|
29 | ToggleButton.prototype.ngAfterViewInit = function () {
|
30 | if (this.checkboxViewChild) {
|
31 | this.checkbox = this.checkboxViewChild.nativeElement;
|
32 | }
|
33 | };
|
34 | ToggleButton.prototype.toggle = function (event) {
|
35 | if (!this.disabled) {
|
36 | this.checked = !this.checked;
|
37 | this.onModelChange(this.checked);
|
38 | this.onModelTouched();
|
39 | this.onChange.emit({
|
40 | originalEvent: event,
|
41 | checked: this.checked
|
42 | });
|
43 | if (this.checkbox) {
|
44 | this.checkbox.focus();
|
45 | }
|
46 | }
|
47 | };
|
48 | ToggleButton.prototype.onFocus = function () {
|
49 | this.focus = true;
|
50 | };
|
51 | ToggleButton.prototype.onBlur = function () {
|
52 | this.focus = false;
|
53 | this.onModelTouched();
|
54 | };
|
55 | ToggleButton.prototype.writeValue = function (value) {
|
56 | this.checked = value;
|
57 | };
|
58 | ToggleButton.prototype.registerOnChange = function (fn) {
|
59 | this.onModelChange = fn;
|
60 | };
|
61 | ToggleButton.prototype.registerOnTouched = function (fn) {
|
62 | this.onModelTouched = fn;
|
63 | };
|
64 | ToggleButton.prototype.setDisabledState = function (val) {
|
65 | this.disabled = val;
|
66 | };
|
67 | Object.defineProperty(ToggleButton.prototype, "hasOnLabel", {
|
68 | get: function () {
|
69 | return this.onLabel && this.onLabel.length > 0;
|
70 | },
|
71 | enumerable: true,
|
72 | configurable: true
|
73 | });
|
74 | Object.defineProperty(ToggleButton.prototype, "hasOffLabel", {
|
75 | get: function () {
|
76 | return this.onLabel && this.onLabel.length > 0;
|
77 | },
|
78 | enumerable: true,
|
79 | configurable: true
|
80 | });
|
81 | __decorate([
|
82 | core.Input()
|
83 | ], ToggleButton.prototype, "onLabel", void 0);
|
84 | __decorate([
|
85 | core.Input()
|
86 | ], ToggleButton.prototype, "offLabel", void 0);
|
87 | __decorate([
|
88 | core.Input()
|
89 | ], ToggleButton.prototype, "onIcon", void 0);
|
90 | __decorate([
|
91 | core.Input()
|
92 | ], ToggleButton.prototype, "offIcon", void 0);
|
93 | __decorate([
|
94 | core.Input()
|
95 | ], ToggleButton.prototype, "ariaLabelledBy", void 0);
|
96 | __decorate([
|
97 | core.Input()
|
98 | ], ToggleButton.prototype, "disabled", void 0);
|
99 | __decorate([
|
100 | core.Input()
|
101 | ], ToggleButton.prototype, "style", void 0);
|
102 | __decorate([
|
103 | core.Input()
|
104 | ], ToggleButton.prototype, "styleClass", void 0);
|
105 | __decorate([
|
106 | core.Input()
|
107 | ], ToggleButton.prototype, "inputId", void 0);
|
108 | __decorate([
|
109 | core.Input()
|
110 | ], ToggleButton.prototype, "tabindex", void 0);
|
111 | __decorate([
|
112 | core.Input()
|
113 | ], ToggleButton.prototype, "iconPos", void 0);
|
114 | __decorate([
|
115 | core.Output()
|
116 | ], ToggleButton.prototype, "onChange", void 0);
|
117 | __decorate([
|
118 | core.ViewChild('checkbox')
|
119 | ], ToggleButton.prototype, "checkboxViewChild", void 0);
|
120 | ToggleButton = __decorate([
|
121 | core.Component({
|
122 | selector: 'p-toggleButton',
|
123 | template: "\n <div [ngClass]=\"{'ui-button ui-togglebutton ui-widget ui-state-default ui-corner-all': true, 'ui-button-text-only': (!onIcon && !offIcon), \n 'ui-button-text-icon-left': (onIcon && offIcon && hasOnLabel && hasOffLabel && iconPos === 'left'), \n 'ui-button-text-icon-right': (onIcon && offIcon && hasOnLabel && hasOffLabel && iconPos === 'right'),'ui-button-icon-only': (onIcon && offIcon && !hasOnLabel && !hasOffLabel),\n 'ui-state-active': checked,'ui-state-focus':focus,'ui-state-disabled':disabled}\" [ngStyle]=\"style\" [class]=\"styleClass\" \n (click)=\"toggle($event)\" (keydown.enter)=\"toggle($event)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #checkbox type=\"checkbox\" [attr.id]=\"inputId\" [checked]=\"checked\" (focus)=\"onFocus()\" (blur)=\"onBlur()\" [attr.tabindex]=\"tabindex\"\n role=\"button\" [attr.aria-pressed]=\"checked\" [attr.aria-labelledby]=\"ariaLabelledBy\">\n </div>\n <span *ngIf=\"onIcon||offIcon\" class=\"ui-button-icon-left\" [class]=\"checked ? this.onIcon : this.offIcon\" [ngClass]=\"{'ui-button-icon-left': (iconPos === 'left'), \n 'ui-button-icon-right': (iconPos === 'right')}\"></span>\n <span class=\"ui-button-text ui-unselectable-text\">{{checked ? hasOnLabel ? onLabel : 'ui-btn' : hasOffLabel ? offLabel : 'ui-btn'}}</span>\n </div>\n ",
|
124 | providers: [TOGGLEBUTTON_VALUE_ACCESSOR],
|
125 | changeDetection: core.ChangeDetectionStrategy.Default
|
126 | })
|
127 | ], ToggleButton);
|
128 | return ToggleButton;
|
129 | }());
|
130 | var ToggleButtonModule = (function () {
|
131 | function ToggleButtonModule() {
|
132 | }
|
133 | ToggleButtonModule = __decorate([
|
134 | core.NgModule({
|
135 | imports: [common.CommonModule],
|
136 | exports: [ToggleButton],
|
137 | declarations: [ToggleButton]
|
138 | })
|
139 | ], ToggleButtonModule);
|
140 | return ToggleButtonModule;
|
141 | }());
|
142 |
|
143 | exports.TOGGLEBUTTON_VALUE_ACCESSOR = TOGGLEBUTTON_VALUE_ACCESSOR;
|
144 | exports.ToggleButton = ToggleButton;
|
145 | exports.ToggleButtonModule = ToggleButtonModule;
|
146 |
|
147 | Object.defineProperty(exports, '__esModule', { value: true });
|
148 |
|
149 | })));
|
150 |
|