tooltip.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /*!
  2. * Bootstrap tooltip.js v4.6.2 (https://getbootstrap.com/)
  3. * Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('popper.js'), require('./util.js')) :
  8. typeof define === 'function' && define.amd ? define(['jquery', 'popper.js', './util'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tooltip = factory(global.jQuery, global.Popper, global.Util));
  10. })(this, (function ($, Popper, Util) { 'use strict';
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. var $__default = /*#__PURE__*/_interopDefaultLegacy($);
  13. var Popper__default = /*#__PURE__*/_interopDefaultLegacy(Popper);
  14. var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
  15. function _defineProperties(target, props) {
  16. for (var i = 0; i < props.length; i++) {
  17. var descriptor = props[i];
  18. descriptor.enumerable = descriptor.enumerable || false;
  19. descriptor.configurable = true;
  20. if ("value" in descriptor) descriptor.writable = true;
  21. Object.defineProperty(target, descriptor.key, descriptor);
  22. }
  23. }
  24. function _createClass(Constructor, protoProps, staticProps) {
  25. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  26. if (staticProps) _defineProperties(Constructor, staticProps);
  27. Object.defineProperty(Constructor, "prototype", {
  28. writable: false
  29. });
  30. return Constructor;
  31. }
  32. function _extends() {
  33. _extends = Object.assign ? Object.assign.bind() : function (target) {
  34. for (var i = 1; i < arguments.length; i++) {
  35. var source = arguments[i];
  36. for (var key in source) {
  37. if (Object.prototype.hasOwnProperty.call(source, key)) {
  38. target[key] = source[key];
  39. }
  40. }
  41. }
  42. return target;
  43. };
  44. return _extends.apply(this, arguments);
  45. }
  46. /**
  47. * --------------------------------------------------------------------------
  48. * Bootstrap (v4.6.2): tools/sanitizer.js
  49. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  50. * --------------------------------------------------------------------------
  51. */
  52. var uriAttrs = ['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href'];
  53. var ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i;
  54. var DefaultWhitelist = {
  55. // Global attributes allowed on any supplied element below.
  56. '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],
  57. a: ['target', 'href', 'title', 'rel'],
  58. area: [],
  59. b: [],
  60. br: [],
  61. col: [],
  62. code: [],
  63. div: [],
  64. em: [],
  65. hr: [],
  66. h1: [],
  67. h2: [],
  68. h3: [],
  69. h4: [],
  70. h5: [],
  71. h6: [],
  72. i: [],
  73. img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],
  74. li: [],
  75. ol: [],
  76. p: [],
  77. pre: [],
  78. s: [],
  79. small: [],
  80. span: [],
  81. sub: [],
  82. sup: [],
  83. strong: [],
  84. u: [],
  85. ul: []
  86. };
  87. /**
  88. * A pattern that recognizes a commonly useful subset of URLs that are safe.
  89. *
  90. * Shoutout to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts
  91. */
  92. var SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^#&/:?]*(?:[#/?]|$))/i;
  93. /**
  94. * A pattern that matches safe data URLs. Only matches image, video and audio types.
  95. *
  96. * Shoutout to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts
  97. */
  98. var DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i;
  99. function allowedAttribute(attr, allowedAttributeList) {
  100. var attrName = attr.nodeName.toLowerCase();
  101. if (allowedAttributeList.indexOf(attrName) !== -1) {
  102. if (uriAttrs.indexOf(attrName) !== -1) {
  103. return Boolean(SAFE_URL_PATTERN.test(attr.nodeValue) || DATA_URL_PATTERN.test(attr.nodeValue));
  104. }
  105. return true;
  106. }
  107. var regExp = allowedAttributeList.filter(function (attrRegex) {
  108. return attrRegex instanceof RegExp;
  109. }); // Check if a regular expression validates the attribute.
  110. for (var i = 0, len = regExp.length; i < len; i++) {
  111. if (regExp[i].test(attrName)) {
  112. return true;
  113. }
  114. }
  115. return false;
  116. }
  117. function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) {
  118. if (unsafeHtml.length === 0) {
  119. return unsafeHtml;
  120. }
  121. if (sanitizeFn && typeof sanitizeFn === 'function') {
  122. return sanitizeFn(unsafeHtml);
  123. }
  124. var domParser = new window.DOMParser();
  125. var createdDocument = domParser.parseFromString(unsafeHtml, 'text/html');
  126. var whitelistKeys = Object.keys(whiteList);
  127. var elements = [].slice.call(createdDocument.body.querySelectorAll('*'));
  128. var _loop = function _loop(i, len) {
  129. var el = elements[i];
  130. var elName = el.nodeName.toLowerCase();
  131. if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) {
  132. el.parentNode.removeChild(el);
  133. return "continue";
  134. }
  135. var attributeList = [].slice.call(el.attributes); // eslint-disable-next-line unicorn/prefer-spread
  136. var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []);
  137. attributeList.forEach(function (attr) {
  138. if (!allowedAttribute(attr, whitelistedAttributes)) {
  139. el.removeAttribute(attr.nodeName);
  140. }
  141. });
  142. };
  143. for (var i = 0, len = elements.length; i < len; i++) {
  144. var _ret = _loop(i);
  145. if (_ret === "continue") continue;
  146. }
  147. return createdDocument.body.innerHTML;
  148. }
  149. /**
  150. * Constants
  151. */
  152. var NAME = 'tooltip';
  153. var VERSION = '4.6.2';
  154. var DATA_KEY = 'bs.tooltip';
  155. var EVENT_KEY = "." + DATA_KEY;
  156. var JQUERY_NO_CONFLICT = $__default["default"].fn[NAME];
  157. var CLASS_PREFIX = 'bs-tooltip';
  158. var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
  159. var DISALLOWED_ATTRIBUTES = ['sanitize', 'whiteList', 'sanitizeFn'];
  160. var CLASS_NAME_FADE = 'fade';
  161. var CLASS_NAME_SHOW = 'show';
  162. var HOVER_STATE_SHOW = 'show';
  163. var HOVER_STATE_OUT = 'out';
  164. var SELECTOR_TOOLTIP_INNER = '.tooltip-inner';
  165. var SELECTOR_ARROW = '.arrow';
  166. var TRIGGER_HOVER = 'hover';
  167. var TRIGGER_FOCUS = 'focus';
  168. var TRIGGER_CLICK = 'click';
  169. var TRIGGER_MANUAL = 'manual';
  170. var AttachmentMap = {
  171. AUTO: 'auto',
  172. TOP: 'top',
  173. RIGHT: 'right',
  174. BOTTOM: 'bottom',
  175. LEFT: 'left'
  176. };
  177. var Default = {
  178. animation: true,
  179. template: '<div class="tooltip" role="tooltip">' + '<div class="arrow"></div>' + '<div class="tooltip-inner"></div></div>',
  180. trigger: 'hover focus',
  181. title: '',
  182. delay: 0,
  183. html: false,
  184. selector: false,
  185. placement: 'top',
  186. offset: 0,
  187. container: false,
  188. fallbackPlacement: 'flip',
  189. boundary: 'scrollParent',
  190. customClass: '',
  191. sanitize: true,
  192. sanitizeFn: null,
  193. whiteList: DefaultWhitelist,
  194. popperConfig: null
  195. };
  196. var DefaultType = {
  197. animation: 'boolean',
  198. template: 'string',
  199. title: '(string|element|function)',
  200. trigger: 'string',
  201. delay: '(number|object)',
  202. html: 'boolean',
  203. selector: '(string|boolean)',
  204. placement: '(string|function)',
  205. offset: '(number|string|function)',
  206. container: '(string|element|boolean)',
  207. fallbackPlacement: '(string|array)',
  208. boundary: '(string|element)',
  209. customClass: '(string|function)',
  210. sanitize: 'boolean',
  211. sanitizeFn: '(null|function)',
  212. whiteList: 'object',
  213. popperConfig: '(null|object)'
  214. };
  215. var Event = {
  216. HIDE: "hide" + EVENT_KEY,
  217. HIDDEN: "hidden" + EVENT_KEY,
  218. SHOW: "show" + EVENT_KEY,
  219. SHOWN: "shown" + EVENT_KEY,
  220. INSERTED: "inserted" + EVENT_KEY,
  221. CLICK: "click" + EVENT_KEY,
  222. FOCUSIN: "focusin" + EVENT_KEY,
  223. FOCUSOUT: "focusout" + EVENT_KEY,
  224. MOUSEENTER: "mouseenter" + EVENT_KEY,
  225. MOUSELEAVE: "mouseleave" + EVENT_KEY
  226. };
  227. /**
  228. * Class definition
  229. */
  230. var Tooltip = /*#__PURE__*/function () {
  231. function Tooltip(element, config) {
  232. if (typeof Popper__default["default"] === 'undefined') {
  233. throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)');
  234. } // Private
  235. this._isEnabled = true;
  236. this._timeout = 0;
  237. this._hoverState = '';
  238. this._activeTrigger = {};
  239. this._popper = null; // Protected
  240. this.element = element;
  241. this.config = this._getConfig(config);
  242. this.tip = null;
  243. this._setListeners();
  244. } // Getters
  245. var _proto = Tooltip.prototype;
  246. // Public
  247. _proto.enable = function enable() {
  248. this._isEnabled = true;
  249. };
  250. _proto.disable = function disable() {
  251. this._isEnabled = false;
  252. };
  253. _proto.toggleEnabled = function toggleEnabled() {
  254. this._isEnabled = !this._isEnabled;
  255. };
  256. _proto.toggle = function toggle(event) {
  257. if (!this._isEnabled) {
  258. return;
  259. }
  260. if (event) {
  261. var dataKey = this.constructor.DATA_KEY;
  262. var context = $__default["default"](event.currentTarget).data(dataKey);
  263. if (!context) {
  264. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  265. $__default["default"](event.currentTarget).data(dataKey, context);
  266. }
  267. context._activeTrigger.click = !context._activeTrigger.click;
  268. if (context._isWithActiveTrigger()) {
  269. context._enter(null, context);
  270. } else {
  271. context._leave(null, context);
  272. }
  273. } else {
  274. if ($__default["default"](this.getTipElement()).hasClass(CLASS_NAME_SHOW)) {
  275. this._leave(null, this);
  276. return;
  277. }
  278. this._enter(null, this);
  279. }
  280. };
  281. _proto.dispose = function dispose() {
  282. clearTimeout(this._timeout);
  283. $__default["default"].removeData(this.element, this.constructor.DATA_KEY);
  284. $__default["default"](this.element).off(this.constructor.EVENT_KEY);
  285. $__default["default"](this.element).closest('.modal').off('hide.bs.modal', this._hideModalHandler);
  286. if (this.tip) {
  287. $__default["default"](this.tip).remove();
  288. }
  289. this._isEnabled = null;
  290. this._timeout = null;
  291. this._hoverState = null;
  292. this._activeTrigger = null;
  293. if (this._popper) {
  294. this._popper.destroy();
  295. }
  296. this._popper = null;
  297. this.element = null;
  298. this.config = null;
  299. this.tip = null;
  300. };
  301. _proto.show = function show() {
  302. var _this = this;
  303. if ($__default["default"](this.element).css('display') === 'none') {
  304. throw new Error('Please use show on visible elements');
  305. }
  306. var showEvent = $__default["default"].Event(this.constructor.Event.SHOW);
  307. if (this.isWithContent() && this._isEnabled) {
  308. $__default["default"](this.element).trigger(showEvent);
  309. var shadowRoot = Util__default["default"].findShadowRoot(this.element);
  310. var isInTheDom = $__default["default"].contains(shadowRoot !== null ? shadowRoot : this.element.ownerDocument.documentElement, this.element);
  311. if (showEvent.isDefaultPrevented() || !isInTheDom) {
  312. return;
  313. }
  314. var tip = this.getTipElement();
  315. var tipId = Util__default["default"].getUID(this.constructor.NAME);
  316. tip.setAttribute('id', tipId);
  317. this.element.setAttribute('aria-describedby', tipId);
  318. this.setContent();
  319. if (this.config.animation) {
  320. $__default["default"](tip).addClass(CLASS_NAME_FADE);
  321. }
  322. var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;
  323. var attachment = this._getAttachment(placement);
  324. this.addAttachmentClass(attachment);
  325. var container = this._getContainer();
  326. $__default["default"](tip).data(this.constructor.DATA_KEY, this);
  327. if (!$__default["default"].contains(this.element.ownerDocument.documentElement, this.tip)) {
  328. $__default["default"](tip).appendTo(container);
  329. }
  330. $__default["default"](this.element).trigger(this.constructor.Event.INSERTED);
  331. this._popper = new Popper__default["default"](this.element, tip, this._getPopperConfig(attachment));
  332. $__default["default"](tip).addClass(CLASS_NAME_SHOW);
  333. $__default["default"](tip).addClass(this.config.customClass); // If this is a touch-enabled device we add extra
  334. // empty mouseover listeners to the body's immediate children;
  335. // only needed because of broken event delegation on iOS
  336. // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
  337. if ('ontouchstart' in document.documentElement) {
  338. $__default["default"](document.body).children().on('mouseover', null, $__default["default"].noop);
  339. }
  340. var complete = function complete() {
  341. if (_this.config.animation) {
  342. _this._fixTransition();
  343. }
  344. var prevHoverState = _this._hoverState;
  345. _this._hoverState = null;
  346. $__default["default"](_this.element).trigger(_this.constructor.Event.SHOWN);
  347. if (prevHoverState === HOVER_STATE_OUT) {
  348. _this._leave(null, _this);
  349. }
  350. };
  351. if ($__default["default"](this.tip).hasClass(CLASS_NAME_FADE)) {
  352. var transitionDuration = Util__default["default"].getTransitionDurationFromElement(this.tip);
  353. $__default["default"](this.tip).one(Util__default["default"].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
  354. } else {
  355. complete();
  356. }
  357. }
  358. };
  359. _proto.hide = function hide(callback) {
  360. var _this2 = this;
  361. var tip = this.getTipElement();
  362. var hideEvent = $__default["default"].Event(this.constructor.Event.HIDE);
  363. var complete = function complete() {
  364. if (_this2._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
  365. tip.parentNode.removeChild(tip);
  366. }
  367. _this2._cleanTipClass();
  368. _this2.element.removeAttribute('aria-describedby');
  369. $__default["default"](_this2.element).trigger(_this2.constructor.Event.HIDDEN);
  370. if (_this2._popper !== null) {
  371. _this2._popper.destroy();
  372. }
  373. if (callback) {
  374. callback();
  375. }
  376. };
  377. $__default["default"](this.element).trigger(hideEvent);
  378. if (hideEvent.isDefaultPrevented()) {
  379. return;
  380. }
  381. $__default["default"](tip).removeClass(CLASS_NAME_SHOW); // If this is a touch-enabled device we remove the extra
  382. // empty mouseover listeners we added for iOS support
  383. if ('ontouchstart' in document.documentElement) {
  384. $__default["default"](document.body).children().off('mouseover', null, $__default["default"].noop);
  385. }
  386. this._activeTrigger[TRIGGER_CLICK] = false;
  387. this._activeTrigger[TRIGGER_FOCUS] = false;
  388. this._activeTrigger[TRIGGER_HOVER] = false;
  389. if ($__default["default"](this.tip).hasClass(CLASS_NAME_FADE)) {
  390. var transitionDuration = Util__default["default"].getTransitionDurationFromElement(tip);
  391. $__default["default"](tip).one(Util__default["default"].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
  392. } else {
  393. complete();
  394. }
  395. this._hoverState = '';
  396. };
  397. _proto.update = function update() {
  398. if (this._popper !== null) {
  399. this._popper.scheduleUpdate();
  400. }
  401. } // Protected
  402. ;
  403. _proto.isWithContent = function isWithContent() {
  404. return Boolean(this.getTitle());
  405. };
  406. _proto.addAttachmentClass = function addAttachmentClass(attachment) {
  407. $__default["default"](this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
  408. };
  409. _proto.getTipElement = function getTipElement() {
  410. this.tip = this.tip || $__default["default"](this.config.template)[0];
  411. return this.tip;
  412. };
  413. _proto.setContent = function setContent() {
  414. var tip = this.getTipElement();
  415. this.setElementContent($__default["default"](tip.querySelectorAll(SELECTOR_TOOLTIP_INNER)), this.getTitle());
  416. $__default["default"](tip).removeClass(CLASS_NAME_FADE + " " + CLASS_NAME_SHOW);
  417. };
  418. _proto.setElementContent = function setElementContent($element, content) {
  419. if (typeof content === 'object' && (content.nodeType || content.jquery)) {
  420. // Content is a DOM node or a jQuery
  421. if (this.config.html) {
  422. if (!$__default["default"](content).parent().is($element)) {
  423. $element.empty().append(content);
  424. }
  425. } else {
  426. $element.text($__default["default"](content).text());
  427. }
  428. return;
  429. }
  430. if (this.config.html) {
  431. if (this.config.sanitize) {
  432. content = sanitizeHtml(content, this.config.whiteList, this.config.sanitizeFn);
  433. }
  434. $element.html(content);
  435. } else {
  436. $element.text(content);
  437. }
  438. };
  439. _proto.getTitle = function getTitle() {
  440. var title = this.element.getAttribute('data-original-title');
  441. if (!title) {
  442. title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
  443. }
  444. return title;
  445. } // Private
  446. ;
  447. _proto._getPopperConfig = function _getPopperConfig(attachment) {
  448. var _this3 = this;
  449. var defaultBsConfig = {
  450. placement: attachment,
  451. modifiers: {
  452. offset: this._getOffset(),
  453. flip: {
  454. behavior: this.config.fallbackPlacement
  455. },
  456. arrow: {
  457. element: SELECTOR_ARROW
  458. },
  459. preventOverflow: {
  460. boundariesElement: this.config.boundary
  461. }
  462. },
  463. onCreate: function onCreate(data) {
  464. if (data.originalPlacement !== data.placement) {
  465. _this3._handlePopperPlacementChange(data);
  466. }
  467. },
  468. onUpdate: function onUpdate(data) {
  469. return _this3._handlePopperPlacementChange(data);
  470. }
  471. };
  472. return _extends({}, defaultBsConfig, this.config.popperConfig);
  473. };
  474. _proto._getOffset = function _getOffset() {
  475. var _this4 = this;
  476. var offset = {};
  477. if (typeof this.config.offset === 'function') {
  478. offset.fn = function (data) {
  479. data.offsets = _extends({}, data.offsets, _this4.config.offset(data.offsets, _this4.element));
  480. return data;
  481. };
  482. } else {
  483. offset.offset = this.config.offset;
  484. }
  485. return offset;
  486. };
  487. _proto._getContainer = function _getContainer() {
  488. if (this.config.container === false) {
  489. return document.body;
  490. }
  491. if (Util__default["default"].isElement(this.config.container)) {
  492. return $__default["default"](this.config.container);
  493. }
  494. return $__default["default"](document).find(this.config.container);
  495. };
  496. _proto._getAttachment = function _getAttachment(placement) {
  497. return AttachmentMap[placement.toUpperCase()];
  498. };
  499. _proto._setListeners = function _setListeners() {
  500. var _this5 = this;
  501. var triggers = this.config.trigger.split(' ');
  502. triggers.forEach(function (trigger) {
  503. if (trigger === 'click') {
  504. $__default["default"](_this5.element).on(_this5.constructor.Event.CLICK, _this5.config.selector, function (event) {
  505. return _this5.toggle(event);
  506. });
  507. } else if (trigger !== TRIGGER_MANUAL) {
  508. var eventIn = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSEENTER : _this5.constructor.Event.FOCUSIN;
  509. var eventOut = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSELEAVE : _this5.constructor.Event.FOCUSOUT;
  510. $__default["default"](_this5.element).on(eventIn, _this5.config.selector, function (event) {
  511. return _this5._enter(event);
  512. }).on(eventOut, _this5.config.selector, function (event) {
  513. return _this5._leave(event);
  514. });
  515. }
  516. });
  517. this._hideModalHandler = function () {
  518. if (_this5.element) {
  519. _this5.hide();
  520. }
  521. };
  522. $__default["default"](this.element).closest('.modal').on('hide.bs.modal', this._hideModalHandler);
  523. if (this.config.selector) {
  524. this.config = _extends({}, this.config, {
  525. trigger: 'manual',
  526. selector: ''
  527. });
  528. } else {
  529. this._fixTitle();
  530. }
  531. };
  532. _proto._fixTitle = function _fixTitle() {
  533. var titleType = typeof this.element.getAttribute('data-original-title');
  534. if (this.element.getAttribute('title') || titleType !== 'string') {
  535. this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
  536. this.element.setAttribute('title', '');
  537. }
  538. };
  539. _proto._enter = function _enter(event, context) {
  540. var dataKey = this.constructor.DATA_KEY;
  541. context = context || $__default["default"](event.currentTarget).data(dataKey);
  542. if (!context) {
  543. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  544. $__default["default"](event.currentTarget).data(dataKey, context);
  545. }
  546. if (event) {
  547. context._activeTrigger[event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER] = true;
  548. }
  549. if ($__default["default"](context.getTipElement()).hasClass(CLASS_NAME_SHOW) || context._hoverState === HOVER_STATE_SHOW) {
  550. context._hoverState = HOVER_STATE_SHOW;
  551. return;
  552. }
  553. clearTimeout(context._timeout);
  554. context._hoverState = HOVER_STATE_SHOW;
  555. if (!context.config.delay || !context.config.delay.show) {
  556. context.show();
  557. return;
  558. }
  559. context._timeout = setTimeout(function () {
  560. if (context._hoverState === HOVER_STATE_SHOW) {
  561. context.show();
  562. }
  563. }, context.config.delay.show);
  564. };
  565. _proto._leave = function _leave(event, context) {
  566. var dataKey = this.constructor.DATA_KEY;
  567. context = context || $__default["default"](event.currentTarget).data(dataKey);
  568. if (!context) {
  569. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  570. $__default["default"](event.currentTarget).data(dataKey, context);
  571. }
  572. if (event) {
  573. context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] = false;
  574. }
  575. if (context._isWithActiveTrigger()) {
  576. return;
  577. }
  578. clearTimeout(context._timeout);
  579. context._hoverState = HOVER_STATE_OUT;
  580. if (!context.config.delay || !context.config.delay.hide) {
  581. context.hide();
  582. return;
  583. }
  584. context._timeout = setTimeout(function () {
  585. if (context._hoverState === HOVER_STATE_OUT) {
  586. context.hide();
  587. }
  588. }, context.config.delay.hide);
  589. };
  590. _proto._isWithActiveTrigger = function _isWithActiveTrigger() {
  591. for (var trigger in this._activeTrigger) {
  592. if (this._activeTrigger[trigger]) {
  593. return true;
  594. }
  595. }
  596. return false;
  597. };
  598. _proto._getConfig = function _getConfig(config) {
  599. var dataAttributes = $__default["default"](this.element).data();
  600. Object.keys(dataAttributes).forEach(function (dataAttr) {
  601. if (DISALLOWED_ATTRIBUTES.indexOf(dataAttr) !== -1) {
  602. delete dataAttributes[dataAttr];
  603. }
  604. });
  605. config = _extends({}, this.constructor.Default, dataAttributes, typeof config === 'object' && config ? config : {});
  606. if (typeof config.delay === 'number') {
  607. config.delay = {
  608. show: config.delay,
  609. hide: config.delay
  610. };
  611. }
  612. if (typeof config.title === 'number') {
  613. config.title = config.title.toString();
  614. }
  615. if (typeof config.content === 'number') {
  616. config.content = config.content.toString();
  617. }
  618. Util__default["default"].typeCheckConfig(NAME, config, this.constructor.DefaultType);
  619. if (config.sanitize) {
  620. config.template = sanitizeHtml(config.template, config.whiteList, config.sanitizeFn);
  621. }
  622. return config;
  623. };
  624. _proto._getDelegateConfig = function _getDelegateConfig() {
  625. var config = {};
  626. if (this.config) {
  627. for (var key in this.config) {
  628. if (this.constructor.Default[key] !== this.config[key]) {
  629. config[key] = this.config[key];
  630. }
  631. }
  632. }
  633. return config;
  634. };
  635. _proto._cleanTipClass = function _cleanTipClass() {
  636. var $tip = $__default["default"](this.getTipElement());
  637. var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);
  638. if (tabClass !== null && tabClass.length) {
  639. $tip.removeClass(tabClass.join(''));
  640. }
  641. };
  642. _proto._handlePopperPlacementChange = function _handlePopperPlacementChange(popperData) {
  643. this.tip = popperData.instance.popper;
  644. this._cleanTipClass();
  645. this.addAttachmentClass(this._getAttachment(popperData.placement));
  646. };
  647. _proto._fixTransition = function _fixTransition() {
  648. var tip = this.getTipElement();
  649. var initConfigAnimation = this.config.animation;
  650. if (tip.getAttribute('x-placement') !== null) {
  651. return;
  652. }
  653. $__default["default"](tip).removeClass(CLASS_NAME_FADE);
  654. this.config.animation = false;
  655. this.hide();
  656. this.show();
  657. this.config.animation = initConfigAnimation;
  658. } // Static
  659. ;
  660. Tooltip._jQueryInterface = function _jQueryInterface(config) {
  661. return this.each(function () {
  662. var $element = $__default["default"](this);
  663. var data = $element.data(DATA_KEY);
  664. var _config = typeof config === 'object' && config;
  665. if (!data && /dispose|hide/.test(config)) {
  666. return;
  667. }
  668. if (!data) {
  669. data = new Tooltip(this, _config);
  670. $element.data(DATA_KEY, data);
  671. }
  672. if (typeof config === 'string') {
  673. if (typeof data[config] === 'undefined') {
  674. throw new TypeError("No method named \"" + config + "\"");
  675. }
  676. data[config]();
  677. }
  678. });
  679. };
  680. _createClass(Tooltip, null, [{
  681. key: "VERSION",
  682. get: function get() {
  683. return VERSION;
  684. }
  685. }, {
  686. key: "Default",
  687. get: function get() {
  688. return Default;
  689. }
  690. }, {
  691. key: "NAME",
  692. get: function get() {
  693. return NAME;
  694. }
  695. }, {
  696. key: "DATA_KEY",
  697. get: function get() {
  698. return DATA_KEY;
  699. }
  700. }, {
  701. key: "Event",
  702. get: function get() {
  703. return Event;
  704. }
  705. }, {
  706. key: "EVENT_KEY",
  707. get: function get() {
  708. return EVENT_KEY;
  709. }
  710. }, {
  711. key: "DefaultType",
  712. get: function get() {
  713. return DefaultType;
  714. }
  715. }]);
  716. return Tooltip;
  717. }();
  718. /**
  719. * jQuery
  720. */
  721. $__default["default"].fn[NAME] = Tooltip._jQueryInterface;
  722. $__default["default"].fn[NAME].Constructor = Tooltip;
  723. $__default["default"].fn[NAME].noConflict = function () {
  724. $__default["default"].fn[NAME] = JQUERY_NO_CONFLICT;
  725. return Tooltip._jQueryInterface;
  726. };
  727. return Tooltip;
  728. }));
  729. //# sourceMappingURL=tooltip.js.map