1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/animations'), require('@angular/common'), require('primeng/api')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/accordion', ['exports', '@angular/core', '@angular/animations', '@angular/common', 'primeng/api'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.accordion = {}), global.ng.core, global.ng.animations, global.ng.common, global.primeng.api));
|
5 | }(this, (function (exports, core, animations, common, api) { '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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
14 | return function (target, key) { decorator(target, key, paramIndex); }
|
15 | };
|
16 | var idx = 0;
|
17 | var AccordionTab = (function () {
|
18 | function AccordionTab(accordion, changeDetector) {
|
19 | this.changeDetector = changeDetector;
|
20 | this.cache = true;
|
21 | this.selectedChange = new core.EventEmitter();
|
22 | this.transitionOptions = '400ms cubic-bezier(0.86, 0, 0.07, 1)';
|
23 | this.id = "ui-accordiontab-" + idx++;
|
24 | this.accordion = accordion;
|
25 | }
|
26 | Object.defineProperty(AccordionTab.prototype, "selected", {
|
27 | get: function () {
|
28 | return this._selected;
|
29 | },
|
30 | set: function (val) {
|
31 | this._selected = val;
|
32 | if (!this.loaded) {
|
33 | this.changeDetector.detectChanges();
|
34 | }
|
35 | },
|
36 | enumerable: true,
|
37 | configurable: true
|
38 | });
|
39 | Object.defineProperty(AccordionTab.prototype, "animating", {
|
40 | get: function () {
|
41 | return this._animating;
|
42 | },
|
43 | set: function (val) {
|
44 | this._animating = val;
|
45 | if (!this.changeDetector.destroyed) {
|
46 | this.changeDetector.detectChanges();
|
47 | }
|
48 | },
|
49 | enumerable: true,
|
50 | configurable: true
|
51 | });
|
52 | AccordionTab.prototype.ngAfterContentInit = function () {
|
53 | var _this = this;
|
54 | this.templates.forEach(function (item) {
|
55 | switch (item.getType()) {
|
56 | case 'content':
|
57 | _this.contentTemplate = item.template;
|
58 | break;
|
59 | default:
|
60 | _this.contentTemplate = item.template;
|
61 | break;
|
62 | }
|
63 | });
|
64 | };
|
65 | AccordionTab.prototype.toggle = function (event) {
|
66 | if (this.disabled || this.animating) {
|
67 | return false;
|
68 | }
|
69 | this.animating = true;
|
70 | var index = this.findTabIndex();
|
71 | if (this.selected) {
|
72 | this.selected = false;
|
73 | this.accordion.onClose.emit({ originalEvent: event, index: index });
|
74 | }
|
75 | else {
|
76 | if (!this.accordion.multiple) {
|
77 | for (var i = 0; i < this.accordion.tabs.length; i++) {
|
78 | this.accordion.tabs[i].selected = false;
|
79 | this.accordion.tabs[i].selectedChange.emit(false);
|
80 | }
|
81 | }
|
82 | this.selected = true;
|
83 | this.loaded = true;
|
84 | this.accordion.onOpen.emit({ originalEvent: event, index: index });
|
85 | }
|
86 | this.selectedChange.emit(this.selected);
|
87 | this.accordion.updateActiveIndex();
|
88 | event.preventDefault();
|
89 | };
|
90 | AccordionTab.prototype.findTabIndex = function () {
|
91 | var index = -1;
|
92 | for (var i = 0; i < this.accordion.tabs.length; i++) {
|
93 | if (this.accordion.tabs[i] == this) {
|
94 | index = i;
|
95 | break;
|
96 | }
|
97 | }
|
98 | return index;
|
99 | };
|
100 | Object.defineProperty(AccordionTab.prototype, "hasHeaderFacet", {
|
101 | get: function () {
|
102 | return this.headerFacet && this.headerFacet.length > 0;
|
103 | },
|
104 | enumerable: true,
|
105 | configurable: true
|
106 | });
|
107 | AccordionTab.prototype.onToggleDone = function (event) {
|
108 | this.animating = false;
|
109 | };
|
110 | AccordionTab.prototype.onKeydown = function (event) {
|
111 | if (event.which === 32 || event.which === 13) {
|
112 | this.toggle(event);
|
113 | event.preventDefault();
|
114 | }
|
115 | };
|
116 | AccordionTab.prototype.ngOnDestroy = function () {
|
117 | this.accordion.tabs.splice(this.findTabIndex(), 1);
|
118 | };
|
119 | AccordionTab.ctorParameters = function () { return [
|
120 | { type: undefined, decorators: [{ type: core.Inject, args: [core.forwardRef(function () { return Accordion; }),] }] },
|
121 | { type: core.ChangeDetectorRef }
|
122 | ]; };
|
123 | __decorate([
|
124 | core.Input()
|
125 | ], AccordionTab.prototype, "header", void 0);
|
126 | __decorate([
|
127 | core.Input()
|
128 | ], AccordionTab.prototype, "disabled", void 0);
|
129 | __decorate([
|
130 | core.Input()
|
131 | ], AccordionTab.prototype, "cache", void 0);
|
132 | __decorate([
|
133 | core.Output()
|
134 | ], AccordionTab.prototype, "selectedChange", void 0);
|
135 | __decorate([
|
136 | core.Input()
|
137 | ], AccordionTab.prototype, "transitionOptions", void 0);
|
138 | __decorate([
|
139 | core.ContentChildren(api.Header)
|
140 | ], AccordionTab.prototype, "headerFacet", void 0);
|
141 | __decorate([
|
142 | core.ContentChildren(api.PrimeTemplate)
|
143 | ], AccordionTab.prototype, "templates", void 0);
|
144 | __decorate([
|
145 | core.Input()
|
146 | ], AccordionTab.prototype, "selected", null);
|
147 | AccordionTab = __decorate([
|
148 | core.Component({
|
149 | selector: 'p-accordionTab',
|
150 | template: "\n <div class=\"ui-accordion-header ui-state-default ui-corner-all\" [ngClass]=\"{'ui-state-active': selected,'ui-state-disabled':disabled}\">\n <a [attr.tabindex]=\"disabled ? -1 : 0\" [attr.id]=\"id\" [attr.aria-controls]=\"id + '-content'\" role=\"tab\" [attr.aria-expanded]=\"selected\" (click)=\"toggle($event)\" \n (keydown)=\"onKeydown($event)\">\n <span class=\"ui-accordion-toggle-icon\" [ngClass]=\"selected ? accordion.collapseIcon : accordion.expandIcon\"></span>\n <span class=\"ui-accordion-header-text\" *ngIf=\"!hasHeaderFacet\">\n {{header}}\n </span>\n <ng-content select=\"p-header\" *ngIf=\"hasHeaderFacet\"></ng-content>\n </a>\n </div>\n <div [attr.id]=\"id + '-content'\" class=\"ui-accordion-content-wrapper\" [@tabContent]=\"selected ? {value: 'visible', params: {transitionParams: animating ? transitionOptions : '0ms', height: '*'}} : {value: 'hidden', params: {transitionParams: transitionOptions, height: '0'}}\" (@tabContent.done)=\"onToggleDone($event)\"\n [ngClass]=\"{'ui-accordion-content-wrapper-overflown': !selected||animating}\" \n role=\"region\" [attr.aria-hidden]=\"!selected\" [attr.aria-labelledby]=\"id\">\n <div class=\"ui-accordion-content ui-widget-content\">\n <ng-content></ng-content>\n <ng-container *ngIf=\"contentTemplate && (cache ? loaded : selected)\">\n <ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n </ng-container>\n </div>\n </div>\n ",
|
151 | animations: [
|
152 | animations.trigger('tabContent', [
|
153 | animations.state('hidden', animations.style({
|
154 | height: '0'
|
155 | })),
|
156 | animations.state('void', animations.style({
|
157 | height: '{{height}}'
|
158 | }), { params: { height: '0' } }),
|
159 | animations.state('visible', animations.style({
|
160 | height: '*'
|
161 | })),
|
162 | animations.transition('visible <=> hidden', animations.animate('{{transitionParams}}')),
|
163 | animations.transition('void => hidden', animations.animate('{{transitionParams}}')),
|
164 | animations.transition('void => visible', animations.animate('{{transitionParams}}'))
|
165 | ])
|
166 | ],
|
167 | changeDetection: core.ChangeDetectionStrategy.Default
|
168 | }),
|
169 | __param(0, core.Inject(core.forwardRef(function () { return Accordion; })))
|
170 | ], AccordionTab);
|
171 | return AccordionTab;
|
172 | }());
|
173 | var Accordion = (function () {
|
174 | function Accordion(el, changeDetector) {
|
175 | this.el = el;
|
176 | this.changeDetector = changeDetector;
|
177 | this.onClose = new core.EventEmitter();
|
178 | this.onOpen = new core.EventEmitter();
|
179 | this.expandIcon = 'pi pi-fw pi-chevron-right';
|
180 | this.collapseIcon = 'pi pi-fw pi-chevron-down';
|
181 | this.activeIndexChange = new core.EventEmitter();
|
182 | this.tabs = [];
|
183 | }
|
184 | Accordion.prototype.ngAfterContentInit = function () {
|
185 | var _this = this;
|
186 | this.initTabs();
|
187 | this.tabListSubscription = this.tabList.changes.subscribe(function (_) {
|
188 | _this.initTabs();
|
189 | _this.changeDetector.markForCheck();
|
190 | });
|
191 | };
|
192 | Accordion.prototype.initTabs = function () {
|
193 | this.tabs = this.tabList.toArray();
|
194 | this.updateSelectionState();
|
195 | };
|
196 | Accordion.prototype.getBlockableElement = function () {
|
197 | return this.el.nativeElement.children[0];
|
198 | };
|
199 | Object.defineProperty(Accordion.prototype, "activeIndex", {
|
200 | get: function () {
|
201 | return this._activeIndex;
|
202 | },
|
203 | set: function (val) {
|
204 | this._activeIndex = val;
|
205 | if (this.preventActiveIndexPropagation) {
|
206 | this.preventActiveIndexPropagation = false;
|
207 | return;
|
208 | }
|
209 | this.updateSelectionState();
|
210 | },
|
211 | enumerable: true,
|
212 | configurable: true
|
213 | });
|
214 | Accordion.prototype.updateSelectionState = function () {
|
215 | if (this.tabs && this.tabs.length && this._activeIndex != null) {
|
216 | for (var i = 0; i < this.tabs.length; i++) {
|
217 | var selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
|
218 | var changed = selected !== this.tabs[i].selected;
|
219 | if (changed) {
|
220 | this.tabs[i].animating = true;
|
221 | this.tabs[i].selected = selected;
|
222 | this.tabs[i].selectedChange.emit(selected);
|
223 | }
|
224 | }
|
225 | }
|
226 | };
|
227 | Accordion.prototype.updateActiveIndex = function () {
|
228 | var _this = this;
|
229 | var index = this.multiple ? [] : null;
|
230 | this.tabs.forEach(function (tab, i) {
|
231 | if (tab.selected) {
|
232 | if (_this.multiple) {
|
233 | index.push(i);
|
234 | }
|
235 | else {
|
236 | index = i;
|
237 | return;
|
238 | }
|
239 | }
|
240 | });
|
241 | this.preventActiveIndexPropagation = true;
|
242 | this.activeIndexChange.emit(index);
|
243 | };
|
244 | Accordion.prototype.ngOnDestroy = function () {
|
245 | if (this.tabListSubscription) {
|
246 | this.tabListSubscription.unsubscribe();
|
247 | }
|
248 | };
|
249 | Accordion.ctorParameters = function () { return [
|
250 | { type: core.ElementRef },
|
251 | { type: core.ChangeDetectorRef }
|
252 | ]; };
|
253 | __decorate([
|
254 | core.Input()
|
255 | ], Accordion.prototype, "multiple", void 0);
|
256 | __decorate([
|
257 | core.Output()
|
258 | ], Accordion.prototype, "onClose", void 0);
|
259 | __decorate([
|
260 | core.Output()
|
261 | ], Accordion.prototype, "onOpen", void 0);
|
262 | __decorate([
|
263 | core.Input()
|
264 | ], Accordion.prototype, "style", void 0);
|
265 | __decorate([
|
266 | core.Input()
|
267 | ], Accordion.prototype, "styleClass", void 0);
|
268 | __decorate([
|
269 | core.Input()
|
270 | ], Accordion.prototype, "expandIcon", void 0);
|
271 | __decorate([
|
272 | core.Input()
|
273 | ], Accordion.prototype, "collapseIcon", void 0);
|
274 | __decorate([
|
275 | core.Output()
|
276 | ], Accordion.prototype, "activeIndexChange", void 0);
|
277 | __decorate([
|
278 | core.ContentChildren(AccordionTab)
|
279 | ], Accordion.prototype, "tabList", void 0);
|
280 | __decorate([
|
281 | core.Input()
|
282 | ], Accordion.prototype, "activeIndex", null);
|
283 | Accordion = __decorate([
|
284 | core.Component({
|
285 | selector: 'p-accordion',
|
286 | template: "\n <div [ngClass]=\"'ui-accordion ui-widget ui-helper-reset'\" [ngStyle]=\"style\" [class]=\"styleClass\" role=\"tablist\">\n <ng-content></ng-content>\n </div>\n "
|
287 | })
|
288 | ], Accordion);
|
289 | return Accordion;
|
290 | }());
|
291 | var AccordionModule = (function () {
|
292 | function AccordionModule() {
|
293 | }
|
294 | AccordionModule = __decorate([
|
295 | core.NgModule({
|
296 | imports: [common.CommonModule],
|
297 | exports: [Accordion, AccordionTab, api.SharedModule],
|
298 | declarations: [Accordion, AccordionTab]
|
299 | })
|
300 | ], AccordionModule);
|
301 | return AccordionModule;
|
302 | }());
|
303 |
|
304 | exports.Accordion = Accordion;
|
305 | exports.AccordionModule = AccordionModule;
|
306 | exports.AccordionTab = AccordionTab;
|
307 |
|
308 | Object.defineProperty(exports, '__esModule', { value: true });
|
309 |
|
310 | })));
|
311 |
|