tooltip.js 26 KB

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