1 | import { Directive, ElementRef, EventEmitter, HostBinding, Input, Output, Renderer } from '@angular/core';
|
2 | export var CollapseDirective = (function () {
|
3 | function CollapseDirective(_el, _renderer) {
|
4 |
|
5 | this.collapsed = new EventEmitter();
|
6 |
|
7 | this.expanded = new EventEmitter();
|
8 |
|
9 | this.isExpanded = true;
|
10 |
|
11 | this.isCollapsed = false;
|
12 |
|
13 | this.isCollapse = true;
|
14 |
|
15 | this.isCollapsing = false;
|
16 | this._el = _el;
|
17 | this._renderer = _renderer;
|
18 | }
|
19 | Object.defineProperty(CollapseDirective.prototype, "collapse", {
|
20 | get: function () {
|
21 | return this.isExpanded;
|
22 | },
|
23 |
|
24 | set: function (value) {
|
25 | this.isExpanded = value;
|
26 | this.toggle();
|
27 | },
|
28 | enumerable: true,
|
29 | configurable: true
|
30 | });
|
31 |
|
32 | CollapseDirective.prototype.toggle = function () {
|
33 | if (this.isExpanded) {
|
34 | this.hide();
|
35 | }
|
36 | else {
|
37 | this.show();
|
38 | }
|
39 | };
|
40 |
|
41 | CollapseDirective.prototype.hide = function () {
|
42 | this.isCollapse = false;
|
43 | this.isCollapsing = true;
|
44 | this.isExpanded = false;
|
45 | this.isCollapsed = true;
|
46 | this.isCollapse = true;
|
47 | this.isCollapsing = false;
|
48 | this.display = 'none';
|
49 | this.collapsed.emit(this);
|
50 | };
|
51 |
|
52 | CollapseDirective.prototype.show = function () {
|
53 | this.isCollapse = false;
|
54 | this.isCollapsing = true;
|
55 | this.isExpanded = true;
|
56 | this.isCollapsed = false;
|
57 | this.display = 'block';
|
58 |
|
59 | this.isCollapse = true;
|
60 | this.isCollapsing = false;
|
61 | this._renderer.setElementStyle(this._el.nativeElement, 'overflow', 'visible');
|
62 | this._renderer.setElementStyle(this._el.nativeElement, 'height', 'auto');
|
63 | this.expanded.emit(this);
|
64 | };
|
65 | CollapseDirective.decorators = [
|
66 | { type: Directive, args: [{
|
67 | selector: '[collapse]',
|
68 | exportAs: 'bs-collapse',
|
69 |
|
70 | host: { '[class.collapse]': 'true' } |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | },] },
|
82 | ];
|
83 |
|
84 | CollapseDirective.ctorParameters = function () { return [
|
85 | { type: ElementRef, },
|
86 | { type: Renderer, },
|
87 | ]; };
|
88 | CollapseDirective.propDecorators = {
|
89 | 'collapsed': [{ type: Output },],
|
90 | 'expanded': [{ type: Output },],
|
91 | 'display': [{ type: HostBinding, args: ['style.display',] },],
|
92 | 'isExpanded': [{ type: HostBinding, args: ['class.in',] }, { type: HostBinding, args: ['class.show',] }, { type: HostBinding, args: ['attr.aria-expanded',] },],
|
93 | 'isCollapsed': [{ type: HostBinding, args: ['attr.aria-hidden',] },],
|
94 | 'isCollapse': [{ type: HostBinding, args: ['class.collapse',] },],
|
95 | 'isCollapsing': [{ type: HostBinding, args: ['class.collapsing',] },],
|
96 | 'collapse': [{ type: Input },],
|
97 | };
|
98 | return CollapseDirective;
|
99 | }());
|
100 |
|
\ | No newline at end of file |