Layout von Websiten mit Bootstrap und Foundation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tooltip.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /*!
  2. * Bootstrap tooltip.js v4.5.0 (https://getbootstrap.com/)
  3. * Copyright 2011-2020 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. $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;
  12. Popper = Popper && Object.prototype.hasOwnProperty.call(Popper, 'default') ? Popper['default'] : Popper;
  13. Util = Util && Object.prototype.hasOwnProperty.call(Util, '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.5.0): 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', 'srcset', '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,[\d+/a-z]+=*$/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, len = regExp.length; i < len; 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.5.0';
  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 HOVER_STATE_SHOW = 'show';
  229. var HOVER_STATE_OUT = 'out';
  230. var Event = {
  231. HIDE: "hide" + EVENT_KEY,
  232. HIDDEN: "hidden" + EVENT_KEY,
  233. SHOW: "show" + EVENT_KEY,
  234. SHOWN: "shown" + EVENT_KEY,
  235. INSERTED: "inserted" + EVENT_KEY,
  236. CLICK: "click" + EVENT_KEY,
  237. FOCUSIN: "focusin" + EVENT_KEY,
  238. FOCUSOUT: "focusout" + EVENT_KEY,
  239. MOUSEENTER: "mouseenter" + EVENT_KEY,
  240. MOUSELEAVE: "mouseleave" + EVENT_KEY
  241. };
  242. var CLASS_NAME_FADE = 'fade';
  243. var CLASS_NAME_SHOW = 'show';
  244. var SELECTOR_TOOLTIP_INNER = '.tooltip-inner';
  245. var SELECTOR_ARROW = '.arrow';
  246. var TRIGGER_HOVER = 'hover';
  247. var TRIGGER_FOCUS = 'focus';
  248. var TRIGGER_CLICK = 'click';
  249. var TRIGGER_MANUAL = 'manual';
  250. /**
  251. * ------------------------------------------------------------------------
  252. * Class Definition
  253. * ------------------------------------------------------------------------
  254. */
  255. var Tooltip = /*#__PURE__*/function () {
  256. function Tooltip(element, config) {
  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(CLASS_NAME_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', this._hideModalHandler);
  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) {
  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(CLASS_NAME_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, this._getPopperConfig(attachment));
  357. $(tip).addClass(CLASS_NAME_SHOW); // If this is a touch-enabled device we add extra
  358. // empty mouseover listeners to the body's immediate children;
  359. // only needed because of broken event delegation on iOS
  360. // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
  361. if ('ontouchstart' in document.documentElement) {
  362. $(document.body).children().on('mouseover', null, $.noop);
  363. }
  364. var complete = function complete() {
  365. if (_this.config.animation) {
  366. _this._fixTransition();
  367. }
  368. var prevHoverState = _this._hoverState;
  369. _this._hoverState = null;
  370. $(_this.element).trigger(_this.constructor.Event.SHOWN);
  371. if (prevHoverState === HOVER_STATE_OUT) {
  372. _this._leave(null, _this);
  373. }
  374. };
  375. if ($(this.tip).hasClass(CLASS_NAME_FADE)) {
  376. var transitionDuration = Util.getTransitionDurationFromElement(this.tip);
  377. $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
  378. } else {
  379. complete();
  380. }
  381. }
  382. };
  383. _proto.hide = function hide(callback) {
  384. var _this2 = this;
  385. var tip = this.getTipElement();
  386. var hideEvent = $.Event(this.constructor.Event.HIDE);
  387. var complete = function complete() {
  388. if (_this2._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
  389. tip.parentNode.removeChild(tip);
  390. }
  391. _this2._cleanTipClass();
  392. _this2.element.removeAttribute('aria-describedby');
  393. $(_this2.element).trigger(_this2.constructor.Event.HIDDEN);
  394. if (_this2._popper !== null) {
  395. _this2._popper.destroy();
  396. }
  397. if (callback) {
  398. callback();
  399. }
  400. };
  401. $(this.element).trigger(hideEvent);
  402. if (hideEvent.isDefaultPrevented()) {
  403. return;
  404. }
  405. $(tip).removeClass(CLASS_NAME_SHOW); // If this is a touch-enabled device we remove the extra
  406. // empty mouseover listeners we added for iOS support
  407. if ('ontouchstart' in document.documentElement) {
  408. $(document.body).children().off('mouseover', null, $.noop);
  409. }
  410. this._activeTrigger[TRIGGER_CLICK] = false;
  411. this._activeTrigger[TRIGGER_FOCUS] = false;
  412. this._activeTrigger[TRIGGER_HOVER] = false;
  413. if ($(this.tip).hasClass(CLASS_NAME_FADE)) {
  414. var transitionDuration = Util.getTransitionDurationFromElement(tip);
  415. $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
  416. } else {
  417. complete();
  418. }
  419. this._hoverState = '';
  420. };
  421. _proto.update = function update() {
  422. if (this._popper !== null) {
  423. this._popper.scheduleUpdate();
  424. }
  425. } // Protected
  426. ;
  427. _proto.isWithContent = function isWithContent() {
  428. return Boolean(this.getTitle());
  429. };
  430. _proto.addAttachmentClass = function addAttachmentClass(attachment) {
  431. $(this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
  432. };
  433. _proto.getTipElement = function getTipElement() {
  434. this.tip = this.tip || $(this.config.template)[0];
  435. return this.tip;
  436. };
  437. _proto.setContent = function setContent() {
  438. var tip = this.getTipElement();
  439. this.setElementContent($(tip.querySelectorAll(SELECTOR_TOOLTIP_INNER)), this.getTitle());
  440. $(tip).removeClass(CLASS_NAME_FADE + " " + CLASS_NAME_SHOW);
  441. };
  442. _proto.setElementContent = function setElementContent($element, content) {
  443. if (typeof content === 'object' && (content.nodeType || content.jquery)) {
  444. // Content is a DOM node or a jQuery
  445. if (this.config.html) {
  446. if (!$(content).parent().is($element)) {
  447. $element.empty().append(content);
  448. }
  449. } else {
  450. $element.text($(content).text());
  451. }
  452. return;
  453. }
  454. if (this.config.html) {
  455. if (this.config.sanitize) {
  456. content = sanitizeHtml(content, this.config.whiteList, this.config.sanitizeFn);
  457. }
  458. $element.html(content);
  459. } else {
  460. $element.text(content);
  461. }
  462. };
  463. _proto.getTitle = function getTitle() {
  464. var title = this.element.getAttribute('data-original-title');
  465. if (!title) {
  466. title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
  467. }
  468. return title;
  469. } // Private
  470. ;
  471. _proto._getPopperConfig = function _getPopperConfig(attachment) {
  472. var _this3 = this;
  473. var defaultBsConfig = {
  474. placement: attachment,
  475. modifiers: {
  476. offset: this._getOffset(),
  477. flip: {
  478. behavior: this.config.fallbackPlacement
  479. },
  480. arrow: {
  481. element: SELECTOR_ARROW
  482. },
  483. preventOverflow: {
  484. boundariesElement: this.config.boundary
  485. }
  486. },
  487. onCreate: function onCreate(data) {
  488. if (data.originalPlacement !== data.placement) {
  489. _this3._handlePopperPlacementChange(data);
  490. }
  491. },
  492. onUpdate: function onUpdate(data) {
  493. return _this3._handlePopperPlacementChange(data);
  494. }
  495. };
  496. return _objectSpread2(_objectSpread2({}, defaultBsConfig), this.config.popperConfig);
  497. };
  498. _proto._getOffset = function _getOffset() {
  499. var _this4 = this;
  500. var offset = {};
  501. if (typeof this.config.offset === 'function') {
  502. offset.fn = function (data) {
  503. data.offsets = _objectSpread2(_objectSpread2({}, data.offsets), _this4.config.offset(data.offsets, _this4.element) || {});
  504. return data;
  505. };
  506. } else {
  507. offset.offset = this.config.offset;
  508. }
  509. return offset;
  510. };
  511. _proto._getContainer = function _getContainer() {
  512. if (this.config.container === false) {
  513. return document.body;
  514. }
  515. if (Util.isElement(this.config.container)) {
  516. return $(this.config.container);
  517. }
  518. return $(document).find(this.config.container);
  519. };
  520. _proto._getAttachment = function _getAttachment(placement) {
  521. return AttachmentMap[placement.toUpperCase()];
  522. };
  523. _proto._setListeners = function _setListeners() {
  524. var _this5 = this;
  525. var triggers = this.config.trigger.split(' ');
  526. triggers.forEach(function (trigger) {
  527. if (trigger === 'click') {
  528. $(_this5.element).on(_this5.constructor.Event.CLICK, _this5.config.selector, function (event) {
  529. return _this5.toggle(event);
  530. });
  531. } else if (trigger !== TRIGGER_MANUAL) {
  532. var eventIn = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSEENTER : _this5.constructor.Event.FOCUSIN;
  533. var eventOut = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSELEAVE : _this5.constructor.Event.FOCUSOUT;
  534. $(_this5.element).on(eventIn, _this5.config.selector, function (event) {
  535. return _this5._enter(event);
  536. }).on(eventOut, _this5.config.selector, function (event) {
  537. return _this5._leave(event);
  538. });
  539. }
  540. });
  541. this._hideModalHandler = function () {
  542. if (_this5.element) {
  543. _this5.hide();
  544. }
  545. };
  546. $(this.element).closest('.modal').on('hide.bs.modal', this._hideModalHandler);
  547. if (this.config.selector) {
  548. this.config = _objectSpread2(_objectSpread2({}, this.config), {}, {
  549. trigger: 'manual',
  550. selector: ''
  551. });
  552. } else {
  553. this._fixTitle();
  554. }
  555. };
  556. _proto._fixTitle = function _fixTitle() {
  557. var titleType = typeof this.element.getAttribute('data-original-title');
  558. if (this.element.getAttribute('title') || titleType !== 'string') {
  559. this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
  560. this.element.setAttribute('title', '');
  561. }
  562. };
  563. _proto._enter = function _enter(event, context) {
  564. var dataKey = this.constructor.DATA_KEY;
  565. context = context || $(event.currentTarget).data(dataKey);
  566. if (!context) {
  567. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  568. $(event.currentTarget).data(dataKey, context);
  569. }
  570. if (event) {
  571. context._activeTrigger[event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER] = true;
  572. }
  573. if ($(context.getTipElement()).hasClass(CLASS_NAME_SHOW) || context._hoverState === HOVER_STATE_SHOW) {
  574. context._hoverState = HOVER_STATE_SHOW;
  575. return;
  576. }
  577. clearTimeout(context._timeout);
  578. context._hoverState = HOVER_STATE_SHOW;
  579. if (!context.config.delay || !context.config.delay.show) {
  580. context.show();
  581. return;
  582. }
  583. context._timeout = setTimeout(function () {
  584. if (context._hoverState === HOVER_STATE_SHOW) {
  585. context.show();
  586. }
  587. }, context.config.delay.show);
  588. };
  589. _proto._leave = function _leave(event, context) {
  590. var dataKey = this.constructor.DATA_KEY;
  591. context = context || $(event.currentTarget).data(dataKey);
  592. if (!context) {
  593. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  594. $(event.currentTarget).data(dataKey, context);
  595. }
  596. if (event) {
  597. context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] = false;
  598. }
  599. if (context._isWithActiveTrigger()) {
  600. return;
  601. }
  602. clearTimeout(context._timeout);
  603. context._hoverState = HOVER_STATE_OUT;
  604. if (!context.config.delay || !context.config.delay.hide) {
  605. context.hide();
  606. return;
  607. }
  608. context._timeout = setTimeout(function () {
  609. if (context._hoverState === HOVER_STATE_OUT) {
  610. context.hide();
  611. }
  612. }, context.config.delay.hide);
  613. };
  614. _proto._isWithActiveTrigger = function _isWithActiveTrigger() {
  615. for (var trigger in this._activeTrigger) {
  616. if (this._activeTrigger[trigger]) {
  617. return true;
  618. }
  619. }
  620. return false;
  621. };
  622. _proto._getConfig = function _getConfig(config) {
  623. var dataAttributes = $(this.element).data();
  624. Object.keys(dataAttributes).forEach(function (dataAttr) {
  625. if (DISALLOWED_ATTRIBUTES.indexOf(dataAttr) !== -1) {
  626. delete dataAttributes[dataAttr];
  627. }
  628. });
  629. config = _objectSpread2(_objectSpread2(_objectSpread2({}, this.constructor.Default), dataAttributes), typeof config === 'object' && config ? config : {});
  630. if (typeof config.delay === 'number') {
  631. config.delay = {
  632. show: config.delay,
  633. hide: config.delay
  634. };
  635. }
  636. if (typeof config.title === 'number') {
  637. config.title = config.title.toString();
  638. }
  639. if (typeof config.content === 'number') {
  640. config.content = config.content.toString();
  641. }
  642. Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
  643. if (config.sanitize) {
  644. config.template = sanitizeHtml(config.template, config.whiteList, config.sanitizeFn);
  645. }
  646. return config;
  647. };
  648. _proto._getDelegateConfig = function _getDelegateConfig() {
  649. var config = {};
  650. if (this.config) {
  651. for (var key in this.config) {
  652. if (this.constructor.Default[key] !== this.config[key]) {
  653. config[key] = this.config[key];
  654. }
  655. }
  656. }
  657. return config;
  658. };
  659. _proto._cleanTipClass = function _cleanTipClass() {
  660. var $tip = $(this.getTipElement());
  661. var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);
  662. if (tabClass !== null && tabClass.length) {
  663. $tip.removeClass(tabClass.join(''));
  664. }
  665. };
  666. _proto._handlePopperPlacementChange = function _handlePopperPlacementChange(popperData) {
  667. this.tip = popperData.instance.popper;
  668. this._cleanTipClass();
  669. this.addAttachmentClass(this._getAttachment(popperData.placement));
  670. };
  671. _proto._fixTransition = function _fixTransition() {
  672. var tip = this.getTipElement();
  673. var initConfigAnimation = this.config.animation;
  674. if (tip.getAttribute('x-placement') !== null) {
  675. return;
  676. }
  677. $(tip).removeClass(CLASS_NAME_FADE);
  678. this.config.animation = false;
  679. this.hide();
  680. this.show();
  681. this.config.animation = initConfigAnimation;
  682. } // Static
  683. ;
  684. Tooltip._jQueryInterface = function _jQueryInterface(config) {
  685. return this.each(function () {
  686. var data = $(this).data(DATA_KEY);
  687. var _config = typeof config === 'object' && config;
  688. if (!data && /dispose|hide/.test(config)) {
  689. return;
  690. }
  691. if (!data) {
  692. data = new Tooltip(this, _config);
  693. $(this).data(DATA_KEY, data);
  694. }
  695. if (typeof config === 'string') {
  696. if (typeof data[config] === 'undefined') {
  697. throw new TypeError("No method named \"" + config + "\"");
  698. }
  699. data[config]();
  700. }
  701. });
  702. };
  703. _createClass(Tooltip, null, [{
  704. key: "VERSION",
  705. get: function get() {
  706. return VERSION;
  707. }
  708. }, {
  709. key: "Default",
  710. get: function get() {
  711. return Default;
  712. }
  713. }, {
  714. key: "NAME",
  715. get: function get() {
  716. return NAME;
  717. }
  718. }, {
  719. key: "DATA_KEY",
  720. get: function get() {
  721. return DATA_KEY;
  722. }
  723. }, {
  724. key: "Event",
  725. get: function get() {
  726. return Event;
  727. }
  728. }, {
  729. key: "EVENT_KEY",
  730. get: function get() {
  731. return EVENT_KEY;
  732. }
  733. }, {
  734. key: "DefaultType",
  735. get: function get() {
  736. return DefaultType;
  737. }
  738. }]);
  739. return Tooltip;
  740. }();
  741. /**
  742. * ------------------------------------------------------------------------
  743. * jQuery
  744. * ------------------------------------------------------------------------
  745. */
  746. $.fn[NAME] = Tooltip._jQueryInterface;
  747. $.fn[NAME].Constructor = Tooltip;
  748. $.fn[NAME].noConflict = function () {
  749. $.fn[NAME] = JQUERY_NO_CONFLICT;
  750. return Tooltip._jQueryInterface;
  751. };
  752. return Tooltip;
  753. })));
  754. //# sourceMappingURL=tooltip.js.map