ngx-bootstrap-dropdown.umd.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('ngx-bootstrap/component-loader'), require('ngx-bootstrap/utils'), require('@angular/animations'), require('ngx-bootstrap/positioning')) :
  3. typeof define === 'function' && define.amd ? define('ngx-bootstrap/dropdown', ['exports', '@angular/core', 'rxjs/operators', 'ngx-bootstrap/component-loader', 'ngx-bootstrap/utils', '@angular/animations', 'ngx-bootstrap/positioning'], factory) :
  4. (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].dropdown = {}), global.ng.core, global.rxjs.operators, global.componentLoader, global.utils, global.ng.animations, global.positioning));
  5. }(this, function (exports, core, operators, componentLoader, utils, animations, positioning) { 'use strict';
  6. /*! *****************************************************************************
  7. Copyright (c) Microsoft Corporation. All rights reserved.
  8. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  9. this file except in compliance with the License. You may obtain a copy of the
  10. License at http://www.apache.org/licenses/LICENSE-2.0
  11. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  13. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  14. MERCHANTABLITY OR NON-INFRINGEMENT.
  15. See the Apache Version 2.0 License for specific language governing permissions
  16. and limitations under the License.
  17. ***************************************************************************** */
  18. function __values(o) {
  19. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  20. if (m) return m.call(o);
  21. return {
  22. next: function () {
  23. if (o && i >= o.length) o = void 0;
  24. return { value: o && o[i++], done: !o };
  25. }
  26. };
  27. }
  28. /**
  29. * @fileoverview added by tsickle
  30. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  31. */
  32. /**
  33. * Default dropdown configuration
  34. */
  35. var BsDropdownConfig = /** @class */ (function () {
  36. function BsDropdownConfig() {
  37. /**
  38. * default dropdown auto closing behavior
  39. */
  40. this.autoClose = true;
  41. /**
  42. * default dropdown auto closing behavior
  43. */
  44. this.insideClick = false;
  45. /**
  46. * turn on/off animation
  47. */
  48. this.isAnimated = false;
  49. }
  50. BsDropdownConfig.decorators = [
  51. { type: core.Injectable }
  52. ];
  53. return BsDropdownConfig;
  54. }());
  55. /**
  56. * @fileoverview added by tsickle
  57. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  58. */
  59. var BsDropdownState = /** @class */ (function () {
  60. function BsDropdownState() {
  61. var _this = this;
  62. this.direction = 'down';
  63. this.isOpenChange = new core.EventEmitter();
  64. this.isDisabledChange = new core.EventEmitter();
  65. this.toggleClick = new core.EventEmitter();
  66. this.dropdownMenu = new Promise((/**
  67. * @param {?} resolve
  68. * @return {?}
  69. */
  70. function (resolve) {
  71. _this.resolveDropdownMenu = resolve;
  72. }));
  73. }
  74. BsDropdownState.decorators = [
  75. { type: core.Injectable }
  76. ];
  77. /** @nocollapse */
  78. BsDropdownState.ctorParameters = function () { return []; };
  79. return BsDropdownState;
  80. }());
  81. /**
  82. * @fileoverview added by tsickle
  83. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  84. */
  85. /** @type {?} */
  86. var DROPDOWN_ANIMATION_TIMING = '220ms cubic-bezier(0, 0, 0.2, 1)';
  87. /** @type {?} */
  88. var dropdownAnimation = [
  89. animations.style({ height: 0, overflow: 'hidden' }),
  90. animations.animate(DROPDOWN_ANIMATION_TIMING, animations.style({ height: '*', overflow: 'hidden' }))
  91. ];
  92. /**
  93. * @fileoverview added by tsickle
  94. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  95. */
  96. var BsDropdownContainerComponent = /** @class */ (function () {
  97. function BsDropdownContainerComponent(_state, cd, _renderer, _element, _builder) {
  98. var _this = this;
  99. this._state = _state;
  100. this.cd = cd;
  101. this._renderer = _renderer;
  102. this._element = _element;
  103. this.isOpen = false;
  104. this._factoryDropDownAnimation = _builder.build(dropdownAnimation);
  105. this._subscription = _state.isOpenChange.subscribe((/**
  106. * @param {?} value
  107. * @return {?}
  108. */
  109. function (value) {
  110. _this.isOpen = value;
  111. /** @type {?} */
  112. var dropdown = _this._element.nativeElement.querySelector('.dropdown-menu');
  113. _this._renderer.addClass(_this._element.nativeElement.querySelector('div'), 'open');
  114. if (dropdown && !utils.isBs3()) {
  115. _this._renderer.addClass(dropdown, 'show');
  116. if (dropdown.classList.contains('dropdown-menu-right')) {
  117. _this._renderer.setStyle(dropdown, 'left', 'auto');
  118. _this._renderer.setStyle(dropdown, 'right', '0');
  119. }
  120. if (_this.direction === 'up') {
  121. _this._renderer.setStyle(dropdown, 'top', 'auto');
  122. _this._renderer.setStyle(dropdown, 'transform', 'translateY(-101%)');
  123. }
  124. }
  125. if (dropdown && _this._state.isAnimated) {
  126. _this._factoryDropDownAnimation.create(dropdown)
  127. .play();
  128. }
  129. _this.cd.markForCheck();
  130. _this.cd.detectChanges();
  131. }));
  132. }
  133. Object.defineProperty(BsDropdownContainerComponent.prototype, "direction", {
  134. get: /**
  135. * @return {?}
  136. */
  137. function () {
  138. return this._state.direction;
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. /** @internal */
  144. /**
  145. * \@internal
  146. * @param {?} el
  147. * @return {?}
  148. */
  149. BsDropdownContainerComponent.prototype._contains = /**
  150. * \@internal
  151. * @param {?} el
  152. * @return {?}
  153. */
  154. function (el) {
  155. return this._element.nativeElement.contains(el);
  156. };
  157. /**
  158. * @return {?}
  159. */
  160. BsDropdownContainerComponent.prototype.ngOnDestroy = /**
  161. * @return {?}
  162. */
  163. function () {
  164. this._subscription.unsubscribe();
  165. };
  166. BsDropdownContainerComponent.decorators = [
  167. { type: core.Component, args: [{
  168. selector: 'bs-dropdown-container',
  169. changeDetection: core.ChangeDetectionStrategy.OnPush,
  170. host: {
  171. style: 'display:block;position: absolute;'
  172. },
  173. template: "\n <div [class.dropup]=\"direction === 'up'\"\n [class.dropdown]=\"direction === 'down'\"\n [class.show]=\"isOpen\"\n [class.open]=\"isOpen\"><ng-content></ng-content>\n </div>\n "
  174. }] }
  175. ];
  176. /** @nocollapse */
  177. BsDropdownContainerComponent.ctorParameters = function () { return [
  178. { type: BsDropdownState },
  179. { type: core.ChangeDetectorRef },
  180. { type: core.Renderer2 },
  181. { type: core.ElementRef },
  182. { type: animations.AnimationBuilder }
  183. ]; };
  184. return BsDropdownContainerComponent;
  185. }());
  186. /**
  187. * @fileoverview added by tsickle
  188. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  189. */
  190. var BsDropdownDirective = /** @class */ (function () {
  191. function BsDropdownDirective(_elementRef, _renderer, _viewContainerRef, _cis, _state, _config, _builder) {
  192. this._elementRef = _elementRef;
  193. this._renderer = _renderer;
  194. this._viewContainerRef = _viewContainerRef;
  195. this._cis = _cis;
  196. this._state = _state;
  197. this._config = _config;
  198. // todo: move to component loader
  199. this._isInlineOpen = false;
  200. this._subscriptions = [];
  201. this._isInited = false;
  202. // set initial dropdown state from config
  203. this._state.autoClose = this._config.autoClose;
  204. this._state.insideClick = this._config.insideClick;
  205. this._state.isAnimated = this._config.isAnimated;
  206. this._factoryDropDownAnimation = _builder.build(dropdownAnimation);
  207. // create dropdown component loader
  208. this._dropdown = this._cis
  209. .createLoader(this._elementRef, this._viewContainerRef, this._renderer)
  210. .provide({ provide: BsDropdownState, useValue: this._state });
  211. this.onShown = this._dropdown.onShown;
  212. this.onHidden = this._dropdown.onHidden;
  213. this.isOpenChange = this._state.isOpenChange;
  214. }
  215. Object.defineProperty(BsDropdownDirective.prototype, "autoClose", {
  216. get: /**
  217. * @return {?}
  218. */
  219. function () {
  220. return this._state.autoClose;
  221. },
  222. /**
  223. * Indicates that dropdown will be closed on item or document click,
  224. * and after pressing ESC
  225. */
  226. set: /**
  227. * Indicates that dropdown will be closed on item or document click,
  228. * and after pressing ESC
  229. * @param {?} value
  230. * @return {?}
  231. */
  232. function (value) {
  233. this._state.autoClose = value;
  234. },
  235. enumerable: true,
  236. configurable: true
  237. });
  238. Object.defineProperty(BsDropdownDirective.prototype, "isAnimated", {
  239. get: /**
  240. * @return {?}
  241. */
  242. function () {
  243. return this._state.isAnimated;
  244. },
  245. /**
  246. * Indicates that dropdown will be animated
  247. */
  248. set: /**
  249. * Indicates that dropdown will be animated
  250. * @param {?} value
  251. * @return {?}
  252. */
  253. function (value) {
  254. this._state.isAnimated = value;
  255. },
  256. enumerable: true,
  257. configurable: true
  258. });
  259. Object.defineProperty(BsDropdownDirective.prototype, "insideClick", {
  260. get: /**
  261. * @return {?}
  262. */
  263. function () {
  264. return this._state.insideClick;
  265. },
  266. /**
  267. * This attribute indicates that the dropdown shouldn't close on inside click when autoClose is set to true
  268. */
  269. set: /**
  270. * This attribute indicates that the dropdown shouldn't close on inside click when autoClose is set to true
  271. * @param {?} value
  272. * @return {?}
  273. */
  274. function (value) {
  275. this._state.insideClick = value;
  276. },
  277. enumerable: true,
  278. configurable: true
  279. });
  280. Object.defineProperty(BsDropdownDirective.prototype, "isDisabled", {
  281. get: /**
  282. * @return {?}
  283. */
  284. function () {
  285. return this._isDisabled;
  286. },
  287. /**
  288. * Disables dropdown toggle and hides dropdown menu if opened
  289. */
  290. set: /**
  291. * Disables dropdown toggle and hides dropdown menu if opened
  292. * @param {?} value
  293. * @return {?}
  294. */
  295. function (value) {
  296. this._isDisabled = value;
  297. this._state.isDisabledChange.emit(value);
  298. if (value) {
  299. this.hide();
  300. }
  301. },
  302. enumerable: true,
  303. configurable: true
  304. });
  305. Object.defineProperty(BsDropdownDirective.prototype, "isOpen", {
  306. /**
  307. * Returns whether or not the popover is currently being shown
  308. */
  309. get: /**
  310. * Returns whether or not the popover is currently being shown
  311. * @return {?}
  312. */
  313. function () {
  314. if (this._showInline) {
  315. return this._isInlineOpen;
  316. }
  317. return this._dropdown.isShown;
  318. },
  319. set: /**
  320. * @param {?} value
  321. * @return {?}
  322. */
  323. function (value) {
  324. if (value) {
  325. this.show();
  326. }
  327. else {
  328. this.hide();
  329. }
  330. },
  331. enumerable: true,
  332. configurable: true
  333. });
  334. Object.defineProperty(BsDropdownDirective.prototype, "isBs4", {
  335. get: /**
  336. * @return {?}
  337. */
  338. function () {
  339. return !utils.isBs3();
  340. },
  341. enumerable: true,
  342. configurable: true
  343. });
  344. Object.defineProperty(BsDropdownDirective.prototype, "_showInline", {
  345. get: /**
  346. * @private
  347. * @return {?}
  348. */
  349. function () {
  350. return !this.container;
  351. },
  352. enumerable: true,
  353. configurable: true
  354. });
  355. /**
  356. * @return {?}
  357. */
  358. BsDropdownDirective.prototype.ngOnInit = /**
  359. * @return {?}
  360. */
  361. function () {
  362. var _this = this;
  363. // fix: seems there are an issue with `routerLinkActive`
  364. // which result in duplicated call ngOnInit without call to ngOnDestroy
  365. // read more: https://github.com/valor-software/ngx-bootstrap/issues/1885
  366. if (this._isInited) {
  367. return;
  368. }
  369. this._isInited = true;
  370. // attach DOM listeners
  371. this._dropdown.listen({
  372. // because of dropdown inline mode
  373. outsideClick: false,
  374. triggers: this.triggers,
  375. show: (/**
  376. * @return {?}
  377. */
  378. function () { return _this.show(); })
  379. });
  380. // toggle visibility on toggle element click
  381. this._subscriptions.push(this._state.toggleClick.subscribe((/**
  382. * @param {?} value
  383. * @return {?}
  384. */
  385. function (value) { return _this.toggle(value); })));
  386. // hide dropdown if set disabled while opened
  387. this._subscriptions.push(this._state.isDisabledChange
  388. .pipe(operators.filter((/**
  389. * @param {?} value
  390. * @return {?}
  391. */
  392. function (value) { return value; })))
  393. .subscribe((/**
  394. * @param {?} value
  395. * @return {?}
  396. */
  397. function (value) { return _this.hide(); })));
  398. };
  399. /**
  400. * Opens an element’s popover. This is considered a “manual” triggering of
  401. * the popover.
  402. */
  403. /**
  404. * Opens an element’s popover. This is considered a “manual” triggering of
  405. * the popover.
  406. * @return {?}
  407. */
  408. BsDropdownDirective.prototype.show = /**
  409. * Opens an element’s popover. This is considered a “manual” triggering of
  410. * the popover.
  411. * @return {?}
  412. */
  413. function () {
  414. var _this = this;
  415. if (this.isOpen || this.isDisabled) {
  416. return;
  417. }
  418. if (this._showInline) {
  419. if (!this._inlinedMenu) {
  420. this._state.dropdownMenu.then((/**
  421. * @param {?} dropdownMenu
  422. * @return {?}
  423. */
  424. function (dropdownMenu) {
  425. _this._dropdown.attachInline(dropdownMenu.viewContainer, dropdownMenu.templateRef);
  426. _this._inlinedMenu = _this._dropdown._inlineViewRef;
  427. _this.addBs4Polyfills();
  428. _this._renderer.addClass(_this._inlinedMenu.rootNodes[0].parentNode, 'open');
  429. _this.playAnimation();
  430. }))
  431. // swallow errors
  432. .catch();
  433. }
  434. this.addBs4Polyfills();
  435. this._isInlineOpen = true;
  436. this.onShown.emit(true);
  437. this._state.isOpenChange.emit(true);
  438. this.playAnimation();
  439. return;
  440. }
  441. this._state.dropdownMenu.then((/**
  442. * @param {?} dropdownMenu
  443. * @return {?}
  444. */
  445. function (dropdownMenu) {
  446. // check direction in which dropdown should be opened
  447. /** @type {?} */
  448. var _dropup = _this.dropup ||
  449. (typeof _this.dropup !== 'undefined' && _this.dropup);
  450. _this._state.direction = _dropup ? 'up' : 'down';
  451. /** @type {?} */
  452. var _placement = _this.placement || (_dropup ? 'top start' : 'bottom start');
  453. // show dropdown
  454. _this._dropdown
  455. .attach(BsDropdownContainerComponent)
  456. .to(_this.container)
  457. .position({ attachment: _placement })
  458. .show({
  459. content: dropdownMenu.templateRef,
  460. placement: _placement
  461. });
  462. _this._state.isOpenChange.emit(true);
  463. }))
  464. // swallow error
  465. .catch();
  466. };
  467. /**
  468. * Closes an element’s popover. This is considered a “manual” triggering of
  469. * the popover.
  470. */
  471. /**
  472. * Closes an element’s popover. This is considered a “manual” triggering of
  473. * the popover.
  474. * @return {?}
  475. */
  476. BsDropdownDirective.prototype.hide = /**
  477. * Closes an element’s popover. This is considered a “manual” triggering of
  478. * the popover.
  479. * @return {?}
  480. */
  481. function () {
  482. if (!this.isOpen) {
  483. return;
  484. }
  485. if (this._showInline) {
  486. this.removeShowClass();
  487. this.removeDropupStyles();
  488. this._isInlineOpen = false;
  489. this.onHidden.emit(true);
  490. }
  491. else {
  492. this._dropdown.hide();
  493. }
  494. this._state.isOpenChange.emit(false);
  495. };
  496. /**
  497. * Toggles an element’s popover. This is considered a “manual” triggering of
  498. * the popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>
  499. * only hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3
  500. */
  501. /**
  502. * Toggles an element’s popover. This is considered a “manual” triggering of
  503. * the popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>
  504. * only hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3
  505. * @param {?=} value
  506. * @return {?}
  507. */
  508. BsDropdownDirective.prototype.toggle = /**
  509. * Toggles an element’s popover. This is considered a “manual” triggering of
  510. * the popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>
  511. * only hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3
  512. * @param {?=} value
  513. * @return {?}
  514. */
  515. function (value) {
  516. if (this.isOpen || !value) {
  517. return this.hide();
  518. }
  519. return this.show();
  520. };
  521. /** @internal */
  522. /**
  523. * \@internal
  524. * @param {?} event
  525. * @return {?}
  526. */
  527. BsDropdownDirective.prototype._contains = /**
  528. * \@internal
  529. * @param {?} event
  530. * @return {?}
  531. */
  532. function (event) {
  533. return this._elementRef.nativeElement.contains(event.target) ||
  534. (this._dropdown.instance && this._dropdown.instance._contains(event.target));
  535. };
  536. /**
  537. * @return {?}
  538. */
  539. BsDropdownDirective.prototype.ngOnDestroy = /**
  540. * @return {?}
  541. */
  542. function () {
  543. var e_1, _a;
  544. try {
  545. // clean up subscriptions and destroy dropdown
  546. for (var _b = __values(this._subscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
  547. var sub = _c.value;
  548. sub.unsubscribe();
  549. }
  550. }
  551. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  552. finally {
  553. try {
  554. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  555. }
  556. finally { if (e_1) throw e_1.error; }
  557. }
  558. this._dropdown.dispose();
  559. };
  560. /**
  561. * @private
  562. * @return {?}
  563. */
  564. BsDropdownDirective.prototype.addBs4Polyfills = /**
  565. * @private
  566. * @return {?}
  567. */
  568. function () {
  569. if (!utils.isBs3()) {
  570. this.addShowClass();
  571. this.checkRightAlignment();
  572. this.addDropupStyles();
  573. }
  574. };
  575. /**
  576. * @private
  577. * @return {?}
  578. */
  579. BsDropdownDirective.prototype.playAnimation = /**
  580. * @private
  581. * @return {?}
  582. */
  583. function () {
  584. if (this._state.isAnimated && this._inlinedMenu) {
  585. this._factoryDropDownAnimation.create(this._inlinedMenu.rootNodes[0])
  586. .play();
  587. }
  588. };
  589. /**
  590. * @private
  591. * @return {?}
  592. */
  593. BsDropdownDirective.prototype.addShowClass = /**
  594. * @private
  595. * @return {?}
  596. */
  597. function () {
  598. if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
  599. this._renderer.addClass(this._inlinedMenu.rootNodes[0], 'show');
  600. }
  601. };
  602. /**
  603. * @private
  604. * @return {?}
  605. */
  606. BsDropdownDirective.prototype.removeShowClass = /**
  607. * @private
  608. * @return {?}
  609. */
  610. function () {
  611. if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
  612. this._renderer.removeClass(this._inlinedMenu.rootNodes[0], 'show');
  613. }
  614. };
  615. /**
  616. * @private
  617. * @return {?}
  618. */
  619. BsDropdownDirective.prototype.checkRightAlignment = /**
  620. * @private
  621. * @return {?}
  622. */
  623. function () {
  624. if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
  625. /** @type {?} */
  626. var isRightAligned = this._inlinedMenu.rootNodes[0].classList.contains('dropdown-menu-right');
  627. this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'left', isRightAligned ? 'auto' : '0');
  628. this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'right', isRightAligned ? '0' : 'auto');
  629. }
  630. };
  631. /**
  632. * @private
  633. * @return {?}
  634. */
  635. BsDropdownDirective.prototype.addDropupStyles = /**
  636. * @private
  637. * @return {?}
  638. */
  639. function () {
  640. if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
  641. // a little hack to not break support of bootstrap 4 beta
  642. this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'top', this.dropup ? 'auto' : '100%');
  643. this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'transform', this.dropup ? 'translateY(-101%)' : 'translateY(0)');
  644. this._renderer.setStyle(this._inlinedMenu.rootNodes[0], 'bottom', 'auto');
  645. }
  646. };
  647. /**
  648. * @private
  649. * @return {?}
  650. */
  651. BsDropdownDirective.prototype.removeDropupStyles = /**
  652. * @private
  653. * @return {?}
  654. */
  655. function () {
  656. if (this._inlinedMenu && this._inlinedMenu.rootNodes[0]) {
  657. this._renderer.removeStyle(this._inlinedMenu.rootNodes[0], 'top');
  658. this._renderer.removeStyle(this._inlinedMenu.rootNodes[0], 'transform');
  659. this._renderer.removeStyle(this._inlinedMenu.rootNodes[0], 'bottom');
  660. }
  661. };
  662. BsDropdownDirective.decorators = [
  663. { type: core.Directive, args: [{
  664. selector: '[bsDropdown],[dropdown]',
  665. exportAs: 'bs-dropdown',
  666. providers: [BsDropdownState],
  667. host: {
  668. '[class.dropup]': 'dropup',
  669. '[class.open]': 'isOpen',
  670. '[class.show]': 'isOpen && isBs4'
  671. }
  672. },] }
  673. ];
  674. /** @nocollapse */
  675. BsDropdownDirective.ctorParameters = function () { return [
  676. { type: core.ElementRef },
  677. { type: core.Renderer2 },
  678. { type: core.ViewContainerRef },
  679. { type: componentLoader.ComponentLoaderFactory },
  680. { type: BsDropdownState },
  681. { type: BsDropdownConfig },
  682. { type: animations.AnimationBuilder }
  683. ]; };
  684. BsDropdownDirective.propDecorators = {
  685. placement: [{ type: core.Input }],
  686. triggers: [{ type: core.Input }],
  687. container: [{ type: core.Input }],
  688. dropup: [{ type: core.Input }],
  689. autoClose: [{ type: core.Input }],
  690. isAnimated: [{ type: core.Input }],
  691. insideClick: [{ type: core.Input }],
  692. isDisabled: [{ type: core.Input }],
  693. isOpen: [{ type: core.Input }],
  694. isOpenChange: [{ type: core.Output }],
  695. onShown: [{ type: core.Output }],
  696. onHidden: [{ type: core.Output }]
  697. };
  698. return BsDropdownDirective;
  699. }());
  700. /**
  701. * @fileoverview added by tsickle
  702. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  703. */
  704. var BsDropdownMenuDirective = /** @class */ (function () {
  705. // tslint:disable:no-any
  706. function BsDropdownMenuDirective(_state, _viewContainer, _templateRef) {
  707. _state.resolveDropdownMenu({
  708. templateRef: _templateRef,
  709. viewContainer: _viewContainer
  710. });
  711. }
  712. BsDropdownMenuDirective.decorators = [
  713. { type: core.Directive, args: [{
  714. selector: '[bsDropdownMenu],[dropdownMenu]',
  715. exportAs: 'bs-dropdown-menu'
  716. },] }
  717. ];
  718. /** @nocollapse */
  719. BsDropdownMenuDirective.ctorParameters = function () { return [
  720. { type: BsDropdownState },
  721. { type: core.ViewContainerRef },
  722. { type: core.TemplateRef }
  723. ]; };
  724. return BsDropdownMenuDirective;
  725. }());
  726. /**
  727. * @fileoverview added by tsickle
  728. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  729. */
  730. var BsDropdownToggleDirective = /** @class */ (function () {
  731. function BsDropdownToggleDirective(_changeDetectorRef, _dropdown, _element, _renderer, _state) {
  732. var _this = this;
  733. this._changeDetectorRef = _changeDetectorRef;
  734. this._dropdown = _dropdown;
  735. this._element = _element;
  736. this._renderer = _renderer;
  737. this._state = _state;
  738. this.isDisabled = null;
  739. this._subscriptions = [];
  740. // sync is open value with state
  741. this._subscriptions.push(this._state.isOpenChange.subscribe((/**
  742. * @param {?} value
  743. * @return {?}
  744. */
  745. function (value) {
  746. _this.isOpen = value;
  747. if (value) {
  748. _this._documentClickListener = _this._renderer.listen('document', 'click', (/**
  749. * @param {?} event
  750. * @return {?}
  751. */
  752. function (event) {
  753. if (_this._state.autoClose && event.button !== 2 &&
  754. !_this._element.nativeElement.contains(event.target) &&
  755. !(_this._state.insideClick && _this._dropdown._contains(event))) {
  756. _this._state.toggleClick.emit(false);
  757. _this._changeDetectorRef.detectChanges();
  758. }
  759. }));
  760. _this._escKeyUpListener = _this._renderer.listen(_this._element.nativeElement, 'keyup.esc', (/**
  761. * @return {?}
  762. */
  763. function () {
  764. if (_this._state.autoClose) {
  765. _this._state.toggleClick.emit(false);
  766. _this._changeDetectorRef.detectChanges();
  767. }
  768. }));
  769. }
  770. else {
  771. _this._documentClickListener();
  772. _this._escKeyUpListener();
  773. }
  774. })));
  775. // populate disabled state
  776. this._subscriptions.push(this._state.isDisabledChange.subscribe((/**
  777. * @param {?} value
  778. * @return {?}
  779. */
  780. function (value) { return (_this.isDisabled = value || null); })));
  781. }
  782. /**
  783. * @return {?}
  784. */
  785. BsDropdownToggleDirective.prototype.onClick = /**
  786. * @return {?}
  787. */
  788. function () {
  789. if (this.isDisabled) {
  790. return;
  791. }
  792. this._state.toggleClick.emit(true);
  793. };
  794. /**
  795. * @return {?}
  796. */
  797. BsDropdownToggleDirective.prototype.ngOnDestroy = /**
  798. * @return {?}
  799. */
  800. function () {
  801. var e_1, _a;
  802. if (this._documentClickListener) {
  803. this._documentClickListener();
  804. }
  805. if (this._escKeyUpListener) {
  806. this._escKeyUpListener();
  807. }
  808. try {
  809. for (var _b = __values(this._subscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
  810. var sub = _c.value;
  811. sub.unsubscribe();
  812. }
  813. }
  814. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  815. finally {
  816. try {
  817. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  818. }
  819. finally { if (e_1) throw e_1.error; }
  820. }
  821. };
  822. BsDropdownToggleDirective.decorators = [
  823. { type: core.Directive, args: [{
  824. selector: '[bsDropdownToggle],[dropdownToggle]',
  825. exportAs: 'bs-dropdown-toggle',
  826. host: {
  827. '[attr.aria-haspopup]': 'true'
  828. }
  829. },] }
  830. ];
  831. /** @nocollapse */
  832. BsDropdownToggleDirective.ctorParameters = function () { return [
  833. { type: core.ChangeDetectorRef },
  834. { type: BsDropdownDirective },
  835. { type: core.ElementRef },
  836. { type: core.Renderer2 },
  837. { type: BsDropdownState }
  838. ]; };
  839. BsDropdownToggleDirective.propDecorators = {
  840. isDisabled: [{ type: core.HostBinding, args: ['attr.disabled',] }],
  841. isOpen: [{ type: core.HostBinding, args: ['attr.aria-expanded',] }],
  842. onClick: [{ type: core.HostListener, args: ['click', [],] }]
  843. };
  844. return BsDropdownToggleDirective;
  845. }());
  846. /**
  847. * @fileoverview added by tsickle
  848. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  849. */
  850. var BsDropdownModule = /** @class */ (function () {
  851. function BsDropdownModule() {
  852. }
  853. // tslint:disable-next-line:no-any
  854. // tslint:disable-next-line:no-any
  855. /**
  856. * @param {?=} config
  857. * @return {?}
  858. */
  859. BsDropdownModule.forRoot =
  860. // tslint:disable-next-line:no-any
  861. /**
  862. * @param {?=} config
  863. * @return {?}
  864. */
  865. function (config) {
  866. return {
  867. ngModule: BsDropdownModule,
  868. providers: [
  869. componentLoader.ComponentLoaderFactory,
  870. positioning.PositioningService,
  871. BsDropdownState,
  872. {
  873. provide: BsDropdownConfig,
  874. useValue: config ? config : { autoClose: true, insideClick: false }
  875. }
  876. ]
  877. };
  878. };
  879. BsDropdownModule.decorators = [
  880. { type: core.NgModule, args: [{
  881. declarations: [
  882. BsDropdownMenuDirective,
  883. BsDropdownToggleDirective,
  884. BsDropdownContainerComponent,
  885. BsDropdownDirective
  886. ],
  887. exports: [
  888. BsDropdownMenuDirective,
  889. BsDropdownToggleDirective,
  890. BsDropdownDirective
  891. ],
  892. entryComponents: [BsDropdownContainerComponent]
  893. },] }
  894. ];
  895. return BsDropdownModule;
  896. }());
  897. exports.BsDropdownConfig = BsDropdownConfig;
  898. exports.BsDropdownContainerComponent = BsDropdownContainerComponent;
  899. exports.BsDropdownDirective = BsDropdownDirective;
  900. exports.BsDropdownMenuDirective = BsDropdownMenuDirective;
  901. exports.BsDropdownModule = BsDropdownModule;
  902. exports.BsDropdownState = BsDropdownState;
  903. exports.BsDropdownToggleDirective = BsDropdownToggleDirective;
  904. Object.defineProperty(exports, '__esModule', { value: true });
  905. }));
  906. //# sourceMappingURL=ngx-bootstrap-dropdown.umd.js.map