ngx-bootstrap-collapse.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import { style, animate, AnimationBuilder } from '@angular/animations';
  2. import { Directive, ElementRef, Renderer2, Output, HostBinding, Input, EventEmitter, NgModule } from '@angular/core';
  3. /**
  4. * @fileoverview added by tsickle
  5. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  6. */
  7. /** @type {?} */
  8. var COLLAPSE_ANIMATION_TIMING = '400ms cubic-bezier(0.4,0.0,0.2,1)';
  9. /** @type {?} */
  10. var expandAnimation = [
  11. style({ height: 0, visibility: 'hidden' }),
  12. animate(COLLAPSE_ANIMATION_TIMING, style({ height: '*', visibility: 'visible' }))
  13. ];
  14. /** @type {?} */
  15. var collapseAnimation = [
  16. style({ height: '*', visibility: 'visible' }),
  17. animate(COLLAPSE_ANIMATION_TIMING, style({ height: 0, visibility: 'hidden' }))
  18. ];
  19. /**
  20. * @fileoverview added by tsickle
  21. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  22. */
  23. var CollapseDirective = /** @class */ (function () {
  24. function CollapseDirective(_el, _renderer, _builder) {
  25. this._el = _el;
  26. this._renderer = _renderer;
  27. /**
  28. * This event fires as soon as content collapses
  29. */
  30. this.collapsed = new EventEmitter();
  31. /**
  32. * This event fires when collapsing is started
  33. */
  34. this.collapses = new EventEmitter();
  35. /**
  36. * This event fires as soon as content becomes visible
  37. */
  38. this.expanded = new EventEmitter();
  39. /**
  40. * This event fires when expansion is started
  41. */
  42. this.expands = new EventEmitter();
  43. // shown
  44. this.isExpanded = true;
  45. // hidden
  46. this.isCollapsed = false;
  47. // stale state
  48. this.isCollapse = true;
  49. // animation state
  50. this.isCollapsing = false;
  51. /**
  52. * turn on/off animation
  53. */
  54. this.isAnimated = false;
  55. this._display = 'block';
  56. this._stylesLoaded = false;
  57. this._COLLAPSE_ACTION_NAME = 'collapse';
  58. this._EXPAND_ACTION_NAME = 'expand';
  59. this._factoryCollapseAnimation = _builder.build(collapseAnimation);
  60. this._factoryExpandAnimation = _builder.build(expandAnimation);
  61. }
  62. Object.defineProperty(CollapseDirective.prototype, "display", {
  63. set: /**
  64. * @param {?} value
  65. * @return {?}
  66. */
  67. function (value) {
  68. if (!this.isAnimated) {
  69. this._renderer.setStyle(this._el.nativeElement, 'display', value);
  70. return;
  71. }
  72. this._display = value;
  73. if (value === 'none') {
  74. this.hide();
  75. return;
  76. }
  77. this.show();
  78. },
  79. enumerable: true,
  80. configurable: true
  81. });
  82. Object.defineProperty(CollapseDirective.prototype, "collapse", {
  83. get: /**
  84. * @return {?}
  85. */
  86. function () {
  87. return this.isExpanded;
  88. },
  89. /** A flag indicating visibility of content (shown or hidden) */
  90. set: /**
  91. * A flag indicating visibility of content (shown or hidden)
  92. * @param {?} value
  93. * @return {?}
  94. */
  95. function (value) {
  96. if (!this._player || this._isAnimationDone) {
  97. this.isExpanded = value;
  98. this.toggle();
  99. }
  100. },
  101. enumerable: true,
  102. configurable: true
  103. });
  104. /**
  105. * @return {?}
  106. */
  107. CollapseDirective.prototype.ngAfterViewChecked = /**
  108. * @return {?}
  109. */
  110. function () {
  111. this._stylesLoaded = true;
  112. if (!this._player || !this._isAnimationDone) {
  113. return;
  114. }
  115. this._player.reset();
  116. this._renderer.setStyle(this._el.nativeElement, 'height', '*');
  117. };
  118. /** allows to manually toggle content visibility */
  119. /**
  120. * allows to manually toggle content visibility
  121. * @return {?}
  122. */
  123. CollapseDirective.prototype.toggle = /**
  124. * allows to manually toggle content visibility
  125. * @return {?}
  126. */
  127. function () {
  128. if (this.isExpanded) {
  129. this.hide();
  130. }
  131. else {
  132. this.show();
  133. }
  134. };
  135. /** allows to manually hide content */
  136. /**
  137. * allows to manually hide content
  138. * @return {?}
  139. */
  140. CollapseDirective.prototype.hide = /**
  141. * allows to manually hide content
  142. * @return {?}
  143. */
  144. function () {
  145. var _this = this;
  146. this.isCollapsing = true;
  147. this.isExpanded = false;
  148. this.isCollapsed = true;
  149. this.isCollapsing = false;
  150. this.collapses.emit(this);
  151. this._isAnimationDone = false;
  152. this.animationRun(this.isAnimated, this._COLLAPSE_ACTION_NAME)((/**
  153. * @return {?}
  154. */
  155. function () {
  156. _this._isAnimationDone = true;
  157. _this.collapsed.emit(_this);
  158. _this._renderer.setStyle(_this._el.nativeElement, 'display', 'none');
  159. }));
  160. };
  161. /** allows to manually show collapsed content */
  162. /**
  163. * allows to manually show collapsed content
  164. * @return {?}
  165. */
  166. CollapseDirective.prototype.show = /**
  167. * allows to manually show collapsed content
  168. * @return {?}
  169. */
  170. function () {
  171. var _this = this;
  172. this._renderer.setStyle(this._el.nativeElement, 'display', this._display);
  173. this.isCollapsing = true;
  174. this.isExpanded = true;
  175. this.isCollapsed = false;
  176. this.isCollapsing = false;
  177. this.expands.emit(this);
  178. this._isAnimationDone = false;
  179. this.animationRun(this.isAnimated, this._EXPAND_ACTION_NAME)((/**
  180. * @return {?}
  181. */
  182. function () {
  183. _this._isAnimationDone = true;
  184. _this.expanded.emit(_this);
  185. }));
  186. };
  187. /**
  188. * @param {?} isAnimated
  189. * @param {?} action
  190. * @return {?}
  191. */
  192. CollapseDirective.prototype.animationRun = /**
  193. * @param {?} isAnimated
  194. * @param {?} action
  195. * @return {?}
  196. */
  197. function (isAnimated, action) {
  198. var _this = this;
  199. if (!isAnimated || !this._stylesLoaded) {
  200. return (/**
  201. * @param {?} callback
  202. * @return {?}
  203. */
  204. function (callback) { return callback(); });
  205. }
  206. this._renderer.setStyle(this._el.nativeElement, 'overflow', 'hidden');
  207. this._renderer.addClass(this._el.nativeElement, 'collapse');
  208. /** @type {?} */
  209. var factoryAnimation = (action === this._EXPAND_ACTION_NAME)
  210. ? this._factoryExpandAnimation
  211. : this._factoryCollapseAnimation;
  212. if (this._player) {
  213. this._player.destroy();
  214. }
  215. this._player = factoryAnimation.create(this._el.nativeElement);
  216. this._player.play();
  217. return (/**
  218. * @param {?} callback
  219. * @return {?}
  220. */
  221. function (callback) { return _this._player.onDone(callback); });
  222. };
  223. CollapseDirective.decorators = [
  224. { type: Directive, args: [{
  225. selector: '[collapse]',
  226. exportAs: 'bs-collapse',
  227. host: {
  228. '[class.collapse]': 'true'
  229. }
  230. },] }
  231. ];
  232. /** @nocollapse */
  233. CollapseDirective.ctorParameters = function () { return [
  234. { type: ElementRef },
  235. { type: Renderer2 },
  236. { type: AnimationBuilder }
  237. ]; };
  238. CollapseDirective.propDecorators = {
  239. collapsed: [{ type: Output }],
  240. collapses: [{ type: Output }],
  241. expanded: [{ type: Output }],
  242. expands: [{ type: Output }],
  243. isExpanded: [{ type: HostBinding, args: ['class.in',] }, { type: HostBinding, args: ['class.show',] }, { type: HostBinding, args: ['attr.aria-expanded',] }],
  244. isCollapsed: [{ type: HostBinding, args: ['attr.aria-hidden',] }],
  245. isCollapse: [{ type: HostBinding, args: ['class.collapse',] }],
  246. isCollapsing: [{ type: HostBinding, args: ['class.collapsing',] }],
  247. display: [{ type: Input }],
  248. isAnimated: [{ type: Input }],
  249. collapse: [{ type: Input }]
  250. };
  251. return CollapseDirective;
  252. }());
  253. /**
  254. * @fileoverview added by tsickle
  255. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  256. */
  257. var CollapseModule = /** @class */ (function () {
  258. function CollapseModule() {
  259. }
  260. /**
  261. * @return {?}
  262. */
  263. CollapseModule.forRoot = /**
  264. * @return {?}
  265. */
  266. function () {
  267. return { ngModule: CollapseModule, providers: [] };
  268. };
  269. CollapseModule.decorators = [
  270. { type: NgModule, args: [{
  271. declarations: [CollapseDirective],
  272. exports: [CollapseDirective]
  273. },] }
  274. ];
  275. return CollapseModule;
  276. }());
  277. export { CollapseDirective, CollapseModule };
  278. //# sourceMappingURL=ngx-bootstrap-collapse.js.map