1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('primeng/dom'), require('@angular/common')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/button', ['exports', '@angular/core', 'primeng/dom', '@angular/common'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.button = {}), global.ng.core, global.primeng.dom, global.ng.common));
|
5 | }(this, (function (exports, core, dom, common) { '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 ButtonDirective = (function () {
|
14 | function ButtonDirective(el) {
|
15 | this.el = el;
|
16 | this.iconPos = 'left';
|
17 | this.cornerStyleClass = 'ui-corner-all';
|
18 | }
|
19 | ButtonDirective.prototype.ngAfterViewInit = function () {
|
20 | dom.DomHandler.addMultipleClasses(this.el.nativeElement, this.getStyleClass());
|
21 | if (this.icon) {
|
22 | var iconElement = document.createElement("span");
|
23 | iconElement.setAttribute("aria-hidden", "true");
|
24 | var iconPosClass = (this.iconPos == 'right') ? 'ui-button-icon-right' : 'ui-button-icon-left';
|
25 | iconElement.className = iconPosClass + ' ui-clickable ' + this.icon;
|
26 | this.el.nativeElement.appendChild(iconElement);
|
27 | }
|
28 | var labelElement = document.createElement("span");
|
29 | if (this.icon && !this.label) {
|
30 | labelElement.setAttribute('aria-hidden', 'true');
|
31 | }
|
32 | labelElement.className = 'ui-button-text ui-clickable';
|
33 | labelElement.appendChild(document.createTextNode(this.label || 'ui-btn'));
|
34 | this.el.nativeElement.appendChild(labelElement);
|
35 | this.initialized = true;
|
36 | };
|
37 | ButtonDirective.prototype.getStyleClass = function () {
|
38 | var styleClass = 'ui-button ui-widget ui-state-default ' + this.cornerStyleClass;
|
39 | if (this.icon) {
|
40 | if (this.label != null && this.label != undefined) {
|
41 | if (this.iconPos == 'left')
|
42 | styleClass = styleClass + ' ui-button-text-icon-left';
|
43 | else
|
44 | styleClass = styleClass + ' ui-button-text-icon-right';
|
45 | }
|
46 | else {
|
47 | styleClass = styleClass + ' ui-button-icon-only';
|
48 | }
|
49 | }
|
50 | else {
|
51 | if (this.label) {
|
52 | styleClass = styleClass + ' ui-button-text-only';
|
53 | }
|
54 | else {
|
55 | styleClass = styleClass + ' ui-button-text-empty';
|
56 | }
|
57 | }
|
58 | return styleClass;
|
59 | };
|
60 | Object.defineProperty(ButtonDirective.prototype, "label", {
|
61 | get: function () {
|
62 | return this._label;
|
63 | },
|
64 | set: function (val) {
|
65 | this._label = val;
|
66 | if (this.initialized) {
|
67 | dom.DomHandler.findSingle(this.el.nativeElement, '.ui-button-text').textContent = this._label;
|
68 | if (!this.icon) {
|
69 | if (this._label) {
|
70 | dom.DomHandler.removeClass(this.el.nativeElement, 'ui-button-text-empty');
|
71 | dom.DomHandler.addClass(this.el.nativeElement, 'ui-button-text-only');
|
72 | }
|
73 | else {
|
74 | dom.DomHandler.addClass(this.el.nativeElement, 'ui-button-text-empty');
|
75 | dom.DomHandler.removeClass(this.el.nativeElement, 'ui-button-text-only');
|
76 | }
|
77 | }
|
78 | }
|
79 | },
|
80 | enumerable: true,
|
81 | configurable: true
|
82 | });
|
83 | Object.defineProperty(ButtonDirective.prototype, "icon", {
|
84 | get: function () {
|
85 | return this._icon;
|
86 | },
|
87 | set: function (val) {
|
88 | this._icon = val;
|
89 | if (this.initialized) {
|
90 | var iconPosClass = (this.iconPos == 'right') ? 'ui-button-icon-right' : 'ui-button-icon-left';
|
91 | dom.DomHandler.findSingle(this.el.nativeElement, '.ui-clickable').className =
|
92 | iconPosClass + ' ui-clickable ' + this.icon;
|
93 | }
|
94 | },
|
95 | enumerable: true,
|
96 | configurable: true
|
97 | });
|
98 | ButtonDirective.prototype.ngOnDestroy = function () {
|
99 | while (this.el.nativeElement.hasChildNodes()) {
|
100 | this.el.nativeElement.removeChild(this.el.nativeElement.lastChild);
|
101 | }
|
102 | this.initialized = false;
|
103 | };
|
104 | ButtonDirective.ctorParameters = function () { return [
|
105 | { type: core.ElementRef }
|
106 | ]; };
|
107 | __decorate([
|
108 | core.Input()
|
109 | ], ButtonDirective.prototype, "iconPos", void 0);
|
110 | __decorate([
|
111 | core.Input()
|
112 | ], ButtonDirective.prototype, "cornerStyleClass", void 0);
|
113 | __decorate([
|
114 | core.Input()
|
115 | ], ButtonDirective.prototype, "label", null);
|
116 | __decorate([
|
117 | core.Input()
|
118 | ], ButtonDirective.prototype, "icon", null);
|
119 | ButtonDirective = __decorate([
|
120 | core.Directive({
|
121 | selector: '[pButton]'
|
122 | })
|
123 | ], ButtonDirective);
|
124 | return ButtonDirective;
|
125 | }());
|
126 | var Button = (function () {
|
127 | function Button() {
|
128 | this.iconPos = 'left';
|
129 | this.onClick = new core.EventEmitter();
|
130 | this.onFocus = new core.EventEmitter();
|
131 | this.onBlur = new core.EventEmitter();
|
132 | }
|
133 | __decorate([
|
134 | core.Input()
|
135 | ], Button.prototype, "type", void 0);
|
136 | __decorate([
|
137 | core.Input()
|
138 | ], Button.prototype, "iconPos", void 0);
|
139 | __decorate([
|
140 | core.Input()
|
141 | ], Button.prototype, "icon", void 0);
|
142 | __decorate([
|
143 | core.Input()
|
144 | ], Button.prototype, "label", void 0);
|
145 | __decorate([
|
146 | core.Input()
|
147 | ], Button.prototype, "disabled", void 0);
|
148 | __decorate([
|
149 | core.Input()
|
150 | ], Button.prototype, "style", void 0);
|
151 | __decorate([
|
152 | core.Input()
|
153 | ], Button.prototype, "styleClass", void 0);
|
154 | __decorate([
|
155 | core.Output()
|
156 | ], Button.prototype, "onClick", void 0);
|
157 | __decorate([
|
158 | core.Output()
|
159 | ], Button.prototype, "onFocus", void 0);
|
160 | __decorate([
|
161 | core.Output()
|
162 | ], Button.prototype, "onBlur", void 0);
|
163 | Button = __decorate([
|
164 | core.Component({
|
165 | selector: 'p-button',
|
166 | template: "\n <button [attr.type]=\"type\" [class]=\"styleClass\" [ngStyle]=\"style\" [disabled]=\"disabled\"\n [ngClass]=\"{'ui-button ui-widget ui-state-default ui-corner-all':true,\n 'ui-button-icon-only': (icon && !label),\n 'ui-button-text-icon-left': (icon && label && iconPos === 'left'),\n 'ui-button-text-icon-right': (icon && label && iconPos === 'right'),\n 'ui-button-text-only': (!icon && label),\n 'ui-button-text-empty': (!icon && !label),\n 'ui-state-disabled': disabled}\"\n (click)=\"onClick.emit($event)\" (focus)=\"onFocus.emit($event)\" (blur)=\"onBlur.emit($event)\">\n <ng-content></ng-content>\n <span [ngClass]=\"{'ui-clickable': true,\n 'ui-button-icon-left': (iconPos === 'left'), \n 'ui-button-icon-right': (iconPos === 'right')}\"\n [class]=\"icon\" *ngIf=\"icon\" [attr.aria-hidden]=\"true\"></span>\n <span class=\"ui-button-text ui-clickable\" [attr.aria-hidden]=\"icon && !label\">{{label||'ui-btn'}}</span>\n </button>\n ",
|
167 | changeDetection: core.ChangeDetectionStrategy.Default
|
168 | })
|
169 | ], Button);
|
170 | return Button;
|
171 | }());
|
172 | var ButtonModule = (function () {
|
173 | function ButtonModule() {
|
174 | }
|
175 | ButtonModule = __decorate([
|
176 | core.NgModule({
|
177 | imports: [common.CommonModule],
|
178 | exports: [ButtonDirective, Button],
|
179 | declarations: [ButtonDirective, Button]
|
180 | })
|
181 | ], ButtonModule);
|
182 | return ButtonModule;
|
183 | }());
|
184 |
|
185 | exports.Button = Button;
|
186 | exports.ButtonDirective = ButtonDirective;
|
187 | exports.ButtonModule = ButtonModule;
|
188 |
|
189 | Object.defineProperty(exports, '__esModule', { value: true });
|
190 |
|
191 | })));
|
192 |
|