tooltip.js 27 KB

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