ngx-bootstrap-tooltip.umd.js 23 KB

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