ngx-bootstrap-tooltip.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. import { Injectable, Component, ChangeDetectionStrategy, Directive, ViewContainerRef, ElementRef, Renderer2, Input, Output, HostBinding, EventEmitter, NgModule } from '@angular/core';
  2. import { isBs3, warnOnce, parseTriggers, OnChange } from 'ngx-bootstrap/utils';
  3. import { __decorate, __metadata } from 'tslib';
  4. import { ComponentLoaderFactory } from 'ngx-bootstrap/component-loader';
  5. import { PositioningService } from 'ngx-bootstrap/positioning';
  6. import { timer } from 'rxjs';
  7. import { CommonModule } from '@angular/common';
  8. /**
  9. * @fileoverview added by tsickle
  10. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  11. */
  12. /**
  13. * Default values provider for tooltip
  14. */
  15. var TooltipConfig = /** @class */ (function () {
  16. function TooltipConfig() {
  17. /**
  18. * sets disable adaptive position
  19. */
  20. this.adaptivePosition = true;
  21. /**
  22. * tooltip placement, supported positions: 'top', 'bottom', 'left', 'right'
  23. */
  24. this.placement = 'top';
  25. /**
  26. * array of event names which triggers tooltip opening
  27. */
  28. this.triggers = 'hover focus';
  29. /**
  30. * delay before showing the tooltip
  31. */
  32. this.delay = 0;
  33. }
  34. TooltipConfig.decorators = [
  35. { type: Injectable }
  36. ];
  37. return TooltipConfig;
  38. }());
  39. /**
  40. * @fileoverview added by tsickle
  41. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  42. */
  43. var TooltipContainerComponent = /** @class */ (function () {
  44. function TooltipContainerComponent(config) {
  45. Object.assign(this, config);
  46. }
  47. Object.defineProperty(TooltipContainerComponent.prototype, "isBs3", {
  48. get: /**
  49. * @return {?}
  50. */
  51. function () {
  52. return isBs3();
  53. },
  54. enumerable: true,
  55. configurable: true
  56. });
  57. /**
  58. * @return {?}
  59. */
  60. TooltipContainerComponent.prototype.ngAfterViewInit = /**
  61. * @return {?}
  62. */
  63. function () {
  64. this.classMap = { in: false, fade: false };
  65. this.classMap[this.placement] = true;
  66. this.classMap["tooltip-" + this.placement] = true;
  67. this.classMap.in = true;
  68. if (this.animation) {
  69. this.classMap.fade = true;
  70. }
  71. if (this.containerClass) {
  72. this.classMap[this.containerClass] = true;
  73. }
  74. };
  75. TooltipContainerComponent.decorators = [
  76. { type: Component, args: [{
  77. selector: 'bs-tooltip-container',
  78. changeDetection: ChangeDetectionStrategy.OnPush,
  79. // tslint:disable-next-line
  80. host: {
  81. '[class]': '"tooltip in tooltip-" + placement + " " + "bs-tooltip-" + placement + " " + placement + " " + containerClass',
  82. '[class.show]': '!isBs3',
  83. '[class.bs3]': 'isBs3',
  84. '[attr.id]': 'this.id',
  85. role: 'tooltip'
  86. },
  87. template: "\n <div class=\"tooltip-arrow arrow\"></div>\n <div class=\"tooltip-inner\"><ng-content></ng-content></div>\n ",
  88. styles: ["\n :host.tooltip {\n display: block;\n pointer-events: none;\n }\n :host.bs3.tooltip.top>.arrow {\n margin-left: -2px;\n }\n :host.bs3.tooltip.bottom {\n margin-top: 0px;\n }\n :host.bs3.bs-tooltip-left, :host.bs3.bs-tooltip-right{\n margin: 0px;\n }\n :host.bs3.bs-tooltip-right .arrow, :host.bs3.bs-tooltip-left .arrow {\n margin: .3rem 0;\n }\n "]
  89. }] }
  90. ];
  91. /** @nocollapse */
  92. TooltipContainerComponent.ctorParameters = function () { return [
  93. { type: TooltipConfig }
  94. ]; };
  95. return TooltipContainerComponent;
  96. }());
  97. /**
  98. * @fileoverview added by tsickle
  99. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  100. */
  101. /** @type {?} */
  102. var id = 0;
  103. var TooltipDirective = /** @class */ (function () {
  104. function TooltipDirective(_viewContainerRef, cis, config, _elementRef, _renderer, _positionService) {
  105. this._elementRef = _elementRef;
  106. this._renderer = _renderer;
  107. this._positionService = _positionService;
  108. this.tooltipId = id++;
  109. /**
  110. * Fired when tooltip content changes
  111. */
  112. /* tslint:disable-next-line:no-any */
  113. this.tooltipChange = new EventEmitter();
  114. /**
  115. * Css class for tooltip container
  116. */
  117. this.containerClass = '';
  118. /**
  119. * @deprecated - removed, will be added to configuration
  120. */
  121. this.tooltipAnimation = true;
  122. /**
  123. * @deprecated
  124. */
  125. this.tooltipFadeDuration = 150;
  126. this.ariaDescribedby = "tooltip-" + this.tooltipId;
  127. /**
  128. * @deprecated
  129. */
  130. this.tooltipStateChanged = new EventEmitter();
  131. this._tooltip = cis
  132. .createLoader(this._elementRef, _viewContainerRef, this._renderer)
  133. .provide({ provide: TooltipConfig, useValue: config });
  134. Object.assign(this, config);
  135. this.onShown = this._tooltip.onShown;
  136. this.onHidden = this._tooltip.onHidden;
  137. }
  138. Object.defineProperty(TooltipDirective.prototype, "isOpen", {
  139. /**
  140. * Returns whether or not the tooltip is currently being shown
  141. */
  142. get: /**
  143. * Returns whether or not the tooltip is currently being shown
  144. * @return {?}
  145. */
  146. function () {
  147. return this._tooltip.isShown;
  148. },
  149. set: /**
  150. * @param {?} value
  151. * @return {?}
  152. */
  153. function (value) {
  154. if (value) {
  155. this.show();
  156. }
  157. else {
  158. this.hide();
  159. }
  160. },
  161. enumerable: true,
  162. configurable: true
  163. });
  164. Object.defineProperty(TooltipDirective.prototype, "htmlContent", {
  165. /** @deprecated - please use `tooltip` instead */
  166. set: /**
  167. * @deprecated - please use `tooltip` instead
  168. * @param {?} value
  169. * @return {?}
  170. */
  171. function (value) {
  172. warnOnce('tooltipHtml was deprecated, please use `tooltip` instead');
  173. this.tooltip = value;
  174. },
  175. enumerable: true,
  176. configurable: true
  177. });
  178. Object.defineProperty(TooltipDirective.prototype, "_placement", {
  179. /** @deprecated - please use `placement` instead */
  180. set: /**
  181. * @deprecated - please use `placement` instead
  182. * @param {?} value
  183. * @return {?}
  184. */
  185. function (value) {
  186. warnOnce('tooltipPlacement was deprecated, please use `placement` instead');
  187. this.placement = value;
  188. },
  189. enumerable: true,
  190. configurable: true
  191. });
  192. Object.defineProperty(TooltipDirective.prototype, "_isOpen", {
  193. get: /**
  194. * @return {?}
  195. */
  196. function () {
  197. warnOnce('tooltipIsOpen was deprecated, please use `isOpen` instead');
  198. return this.isOpen;
  199. },
  200. /** @deprecated - please use `isOpen` instead */
  201. set: /**
  202. * @deprecated - please use `isOpen` instead
  203. * @param {?} value
  204. * @return {?}
  205. */
  206. function (value) {
  207. warnOnce('tooltipIsOpen was deprecated, please use `isOpen` instead');
  208. this.isOpen = value;
  209. },
  210. enumerable: true,
  211. configurable: true
  212. });
  213. Object.defineProperty(TooltipDirective.prototype, "_enable", {
  214. get: /**
  215. * @return {?}
  216. */
  217. function () {
  218. warnOnce('tooltipEnable was deprecated, please use `isDisabled` instead');
  219. return this.isDisabled;
  220. },
  221. /** @deprecated - please use `isDisabled` instead */
  222. set: /**
  223. * @deprecated - please use `isDisabled` instead
  224. * @param {?} value
  225. * @return {?}
  226. */
  227. function (value) {
  228. warnOnce('tooltipEnable was deprecated, please use `isDisabled` instead');
  229. this.isDisabled = !value;
  230. },
  231. enumerable: true,
  232. configurable: true
  233. });
  234. Object.defineProperty(TooltipDirective.prototype, "_appendToBody", {
  235. get: /**
  236. * @return {?}
  237. */
  238. function () {
  239. warnOnce('tooltipAppendToBody was deprecated, please use `container="body"` instead');
  240. return this.container === 'body';
  241. },
  242. /** @deprecated - please use `container="body"` instead */
  243. set: /**
  244. * @deprecated - please use `container="body"` instead
  245. * @param {?} value
  246. * @return {?}
  247. */
  248. function (value) {
  249. warnOnce('tooltipAppendToBody was deprecated, please use `container="body"` instead');
  250. this.container = value ? 'body' : this.container;
  251. },
  252. enumerable: true,
  253. configurable: true
  254. });
  255. Object.defineProperty(TooltipDirective.prototype, "_popupClass", {
  256. /** @deprecated - will replaced with customClass */
  257. set: /**
  258. * @deprecated - will replaced with customClass
  259. * @param {?} value
  260. * @return {?}
  261. */
  262. function (value) {
  263. warnOnce('tooltipClass deprecated');
  264. },
  265. enumerable: true,
  266. configurable: true
  267. });
  268. Object.defineProperty(TooltipDirective.prototype, "_tooltipContext", {
  269. /** @deprecated - removed */
  270. set: /**
  271. * @deprecated - removed
  272. * @param {?} value
  273. * @return {?}
  274. */
  275. function (value) {
  276. warnOnce('tooltipContext deprecated');
  277. },
  278. enumerable: true,
  279. configurable: true
  280. });
  281. Object.defineProperty(TooltipDirective.prototype, "_tooltipPopupDelay", {
  282. /** @deprecated */
  283. set: /**
  284. * @deprecated
  285. * @param {?} value
  286. * @return {?}
  287. */
  288. function (value) {
  289. warnOnce('tooltipPopupDelay is deprecated, use `delay` instead');
  290. this.delay = value;
  291. },
  292. enumerable: true,
  293. configurable: true
  294. });
  295. Object.defineProperty(TooltipDirective.prototype, "_tooltipTrigger", {
  296. /** @deprecated - please use `triggers` instead */
  297. get: /**
  298. * @deprecated - please use `triggers` instead
  299. * @return {?}
  300. */
  301. function () {
  302. warnOnce('tooltipTrigger was deprecated, please use `triggers` instead');
  303. return this.triggers;
  304. },
  305. set: /**
  306. * @param {?} value
  307. * @return {?}
  308. */
  309. function (value) {
  310. warnOnce('tooltipTrigger was deprecated, please use `triggers` instead');
  311. this.triggers = (value || '').toString();
  312. },
  313. enumerable: true,
  314. configurable: true
  315. });
  316. /**
  317. * @return {?}
  318. */
  319. TooltipDirective.prototype.ngOnInit = /**
  320. * @return {?}
  321. */
  322. function () {
  323. var _this = this;
  324. this._tooltip.listen({
  325. triggers: this.triggers,
  326. show: (/**
  327. * @return {?}
  328. */
  329. function () { return _this.show(); })
  330. });
  331. /* tslint:disable-next-line:no-any */
  332. this.tooltipChange.subscribe((/**
  333. * @param {?} value
  334. * @return {?}
  335. */
  336. function (value) {
  337. if (!value) {
  338. _this._tooltip.hide();
  339. }
  340. }));
  341. };
  342. /**
  343. * Toggles an element’s tooltip. This is considered a “manual” triggering of
  344. * the tooltip.
  345. */
  346. /**
  347. * Toggles an element’s tooltip. This is considered a “manual” triggering of
  348. * the tooltip.
  349. * @return {?}
  350. */
  351. TooltipDirective.prototype.toggle = /**
  352. * Toggles an element’s tooltip. This is considered a “manual” triggering of
  353. * the tooltip.
  354. * @return {?}
  355. */
  356. function () {
  357. if (this.isOpen) {
  358. return this.hide();
  359. }
  360. this.show();
  361. };
  362. /**
  363. * Opens an element’s tooltip. This is considered a “manual” triggering of
  364. * the tooltip.
  365. */
  366. /**
  367. * Opens an element’s tooltip. This is considered a “manual” triggering of
  368. * the tooltip.
  369. * @return {?}
  370. */
  371. TooltipDirective.prototype.show = /**
  372. * Opens an element’s tooltip. This is considered a “manual” triggering of
  373. * the tooltip.
  374. * @return {?}
  375. */
  376. function () {
  377. var _this = this;
  378. this._positionService.setOptions({
  379. modifiers: {
  380. flip: {
  381. enabled: this.adaptivePosition
  382. },
  383. preventOverflow: {
  384. enabled: this.adaptivePosition
  385. }
  386. }
  387. });
  388. if (this.isOpen ||
  389. this.isDisabled ||
  390. this._delayTimeoutId ||
  391. !this.tooltip) {
  392. return;
  393. }
  394. /** @type {?} */
  395. var showTooltip = (/**
  396. * @return {?}
  397. */
  398. function () {
  399. if (_this._delayTimeoutId) {
  400. _this._delayTimeoutId = undefined;
  401. }
  402. _this._tooltip
  403. .attach(TooltipContainerComponent)
  404. .to(_this.container)
  405. .position({ attachment: _this.placement })
  406. .show({
  407. content: _this.tooltip,
  408. placement: _this.placement,
  409. containerClass: _this.containerClass,
  410. id: _this.ariaDescribedby
  411. });
  412. });
  413. /** @type {?} */
  414. var cancelDelayedTooltipShowing = (/**
  415. * @return {?}
  416. */
  417. function () {
  418. if (_this._tooltipCancelShowFn) {
  419. _this._tooltipCancelShowFn();
  420. }
  421. });
  422. if (this.delay) {
  423. /** @type {?} */
  424. var _timer_1 = timer(this.delay).subscribe((/**
  425. * @return {?}
  426. */
  427. function () {
  428. showTooltip();
  429. cancelDelayedTooltipShowing();
  430. }));
  431. if (this.triggers) {
  432. parseTriggers(this.triggers)
  433. .forEach((/**
  434. * @param {?} trigger
  435. * @return {?}
  436. */
  437. function (trigger) {
  438. _this._tooltipCancelShowFn = _this._renderer.listen(_this._elementRef.nativeElement, trigger.close, (/**
  439. * @return {?}
  440. */
  441. function () {
  442. _timer_1.unsubscribe();
  443. cancelDelayedTooltipShowing();
  444. }));
  445. }));
  446. }
  447. }
  448. else {
  449. showTooltip();
  450. }
  451. };
  452. /**
  453. * Closes an element’s tooltip. This is considered a “manual” triggering of
  454. * the tooltip.
  455. */
  456. /**
  457. * Closes an element’s tooltip. This is considered a “manual” triggering of
  458. * the tooltip.
  459. * @return {?}
  460. */
  461. TooltipDirective.prototype.hide = /**
  462. * Closes an element’s tooltip. This is considered a “manual” triggering of
  463. * the tooltip.
  464. * @return {?}
  465. */
  466. function () {
  467. var _this = this;
  468. if (this._delayTimeoutId) {
  469. clearTimeout(this._delayTimeoutId);
  470. this._delayTimeoutId = undefined;
  471. }
  472. if (!this._tooltip.isShown) {
  473. return;
  474. }
  475. this._tooltip.instance.classMap.in = false;
  476. setTimeout((/**
  477. * @return {?}
  478. */
  479. function () {
  480. _this._tooltip.hide();
  481. }), this.tooltipFadeDuration);
  482. };
  483. /**
  484. * @return {?}
  485. */
  486. TooltipDirective.prototype.ngOnDestroy = /**
  487. * @return {?}
  488. */
  489. function () {
  490. this._tooltip.dispose();
  491. };
  492. TooltipDirective.decorators = [
  493. { type: Directive, args: [{
  494. selector: '[tooltip], [tooltipHtml]',
  495. exportAs: 'bs-tooltip'
  496. },] }
  497. ];
  498. /** @nocollapse */
  499. TooltipDirective.ctorParameters = function () { return [
  500. { type: ViewContainerRef },
  501. { type: ComponentLoaderFactory },
  502. { type: TooltipConfig },
  503. { type: ElementRef },
  504. { type: Renderer2 },
  505. { type: PositioningService }
  506. ]; };
  507. TooltipDirective.propDecorators = {
  508. adaptivePosition: [{ type: Input }],
  509. tooltip: [{ type: Input }],
  510. tooltipChange: [{ type: Output }],
  511. placement: [{ type: Input }],
  512. triggers: [{ type: Input }],
  513. container: [{ type: Input }],
  514. containerClass: [{ type: Input }],
  515. isOpen: [{ type: Input }],
  516. isDisabled: [{ type: Input }],
  517. delay: [{ type: Input }],
  518. onShown: [{ type: Output }],
  519. onHidden: [{ type: Output }],
  520. htmlContent: [{ type: Input, args: ['tooltipHtml',] }],
  521. _placement: [{ type: Input, args: ['tooltipPlacement',] }],
  522. _isOpen: [{ type: Input, args: ['tooltipIsOpen',] }],
  523. _enable: [{ type: Input, args: ['tooltipEnable',] }],
  524. _appendToBody: [{ type: Input, args: ['tooltipAppendToBody',] }],
  525. tooltipAnimation: [{ type: Input }],
  526. _popupClass: [{ type: Input, args: ['tooltipClass',] }],
  527. _tooltipContext: [{ type: Input, args: ['tooltipContext',] }],
  528. _tooltipPopupDelay: [{ type: Input, args: ['tooltipPopupDelay',] }],
  529. tooltipFadeDuration: [{ type: Input }],
  530. _tooltipTrigger: [{ type: Input, args: ['tooltipTrigger',] }],
  531. ariaDescribedby: [{ type: HostBinding, args: ['attr.aria-describedby',] }],
  532. tooltipStateChanged: [{ type: Output }]
  533. };
  534. __decorate([
  535. OnChange(),
  536. __metadata("design:type", Object)
  537. ], TooltipDirective.prototype, "tooltip", void 0);
  538. return TooltipDirective;
  539. }());
  540. /**
  541. * @fileoverview added by tsickle
  542. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  543. */
  544. var TooltipModule = /** @class */ (function () {
  545. function TooltipModule() {
  546. }
  547. /**
  548. * @return {?}
  549. */
  550. TooltipModule.forRoot = /**
  551. * @return {?}
  552. */
  553. function () {
  554. return {
  555. ngModule: TooltipModule,
  556. providers: [TooltipConfig, ComponentLoaderFactory, PositioningService]
  557. };
  558. };
  559. TooltipModule.decorators = [
  560. { type: NgModule, args: [{
  561. imports: [CommonModule],
  562. declarations: [TooltipDirective, TooltipContainerComponent],
  563. exports: [TooltipDirective],
  564. entryComponents: [TooltipContainerComponent]
  565. },] }
  566. ];
  567. return TooltipModule;
  568. }());
  569. export { TooltipConfig, TooltipContainerComponent, TooltipDirective, TooltipModule };
  570. //# sourceMappingURL=ngx-bootstrap-tooltip.js.map