ngx-bootstrap-collapse.umd.js 11 KB

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