popover.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*!
  2. * Bootstrap popover.js v5.0.2 (https://getbootstrap.com/)
  3. * Copyright 2011-2021 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('./dom/selector-engine.js'), require('./tooltip.js')) :
  8. typeof define === 'function' && define.amd ? define(['./dom/selector-engine', './tooltip'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Popover = factory(global.SelectorEngine, global.Tooltip));
  10. }(this, (function (SelectorEngine, Tooltip) { 'use strict';
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
  13. var Tooltip__default = /*#__PURE__*/_interopDefaultLegacy(Tooltip);
  14. const getjQuery = () => {
  15. const {
  16. jQuery
  17. } = window;
  18. if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
  19. return jQuery;
  20. }
  21. return null;
  22. };
  23. const DOMContentLoadedCallbacks = [];
  24. const onDOMContentLoaded = callback => {
  25. if (document.readyState === 'loading') {
  26. // add listener on the first call when the document is in loading state
  27. if (!DOMContentLoadedCallbacks.length) {
  28. document.addEventListener('DOMContentLoaded', () => {
  29. DOMContentLoadedCallbacks.forEach(callback => callback());
  30. });
  31. }
  32. DOMContentLoadedCallbacks.push(callback);
  33. } else {
  34. callback();
  35. }
  36. };
  37. const defineJQueryPlugin = plugin => {
  38. onDOMContentLoaded(() => {
  39. const $ = getjQuery();
  40. /* istanbul ignore if */
  41. if ($) {
  42. const name = plugin.NAME;
  43. const JQUERY_NO_CONFLICT = $.fn[name];
  44. $.fn[name] = plugin.jQueryInterface;
  45. $.fn[name].Constructor = plugin;
  46. $.fn[name].noConflict = () => {
  47. $.fn[name] = JQUERY_NO_CONFLICT;
  48. return plugin.jQueryInterface;
  49. };
  50. }
  51. });
  52. };
  53. /**
  54. * --------------------------------------------------------------------------
  55. * Bootstrap (v5.0.2): popover.js
  56. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  57. * --------------------------------------------------------------------------
  58. */
  59. /**
  60. * ------------------------------------------------------------------------
  61. * Constants
  62. * ------------------------------------------------------------------------
  63. */
  64. const NAME = 'popover';
  65. const DATA_KEY = 'bs.popover';
  66. const EVENT_KEY = `.${DATA_KEY}`;
  67. const CLASS_PREFIX = 'bs-popover';
  68. const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g');
  69. const Default = { ...Tooltip__default['default'].Default,
  70. placement: 'right',
  71. offset: [0, 8],
  72. trigger: 'click',
  73. content: '',
  74. template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div>' + '</div>'
  75. };
  76. const DefaultType = { ...Tooltip__default['default'].DefaultType,
  77. content: '(string|element|function)'
  78. };
  79. const Event = {
  80. HIDE: `hide${EVENT_KEY}`,
  81. HIDDEN: `hidden${EVENT_KEY}`,
  82. SHOW: `show${EVENT_KEY}`,
  83. SHOWN: `shown${EVENT_KEY}`,
  84. INSERTED: `inserted${EVENT_KEY}`,
  85. CLICK: `click${EVENT_KEY}`,
  86. FOCUSIN: `focusin${EVENT_KEY}`,
  87. FOCUSOUT: `focusout${EVENT_KEY}`,
  88. MOUSEENTER: `mouseenter${EVENT_KEY}`,
  89. MOUSELEAVE: `mouseleave${EVENT_KEY}`
  90. };
  91. const CLASS_NAME_FADE = 'fade';
  92. const CLASS_NAME_SHOW = 'show';
  93. const SELECTOR_TITLE = '.popover-header';
  94. const SELECTOR_CONTENT = '.popover-body';
  95. /**
  96. * ------------------------------------------------------------------------
  97. * Class Definition
  98. * ------------------------------------------------------------------------
  99. */
  100. class Popover extends Tooltip__default['default'] {
  101. // Getters
  102. static get Default() {
  103. return Default;
  104. }
  105. static get NAME() {
  106. return NAME;
  107. }
  108. static get Event() {
  109. return Event;
  110. }
  111. static get DefaultType() {
  112. return DefaultType;
  113. } // Overrides
  114. isWithContent() {
  115. return this.getTitle() || this._getContent();
  116. }
  117. getTipElement() {
  118. if (this.tip) {
  119. return this.tip;
  120. }
  121. this.tip = super.getTipElement();
  122. if (!this.getTitle()) {
  123. SelectorEngine__default['default'].findOne(SELECTOR_TITLE, this.tip).remove();
  124. }
  125. if (!this._getContent()) {
  126. SelectorEngine__default['default'].findOne(SELECTOR_CONTENT, this.tip).remove();
  127. }
  128. return this.tip;
  129. }
  130. setContent() {
  131. const tip = this.getTipElement(); // we use append for html objects to maintain js events
  132. this.setElementContent(SelectorEngine__default['default'].findOne(SELECTOR_TITLE, tip), this.getTitle());
  133. let content = this._getContent();
  134. if (typeof content === 'function') {
  135. content = content.call(this._element);
  136. }
  137. this.setElementContent(SelectorEngine__default['default'].findOne(SELECTOR_CONTENT, tip), content);
  138. tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW);
  139. } // Private
  140. _addAttachmentClass(attachment) {
  141. this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`);
  142. }
  143. _getContent() {
  144. return this._element.getAttribute('data-bs-content') || this._config.content;
  145. }
  146. _cleanTipClass() {
  147. const tip = this.getTipElement();
  148. const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX);
  149. if (tabClass !== null && tabClass.length > 0) {
  150. tabClass.map(token => token.trim()).forEach(tClass => tip.classList.remove(tClass));
  151. }
  152. } // Static
  153. static jQueryInterface(config) {
  154. return this.each(function () {
  155. const data = Popover.getOrCreateInstance(this, config);
  156. if (typeof config === 'string') {
  157. if (typeof data[config] === 'undefined') {
  158. throw new TypeError(`No method named "${config}"`);
  159. }
  160. data[config]();
  161. }
  162. });
  163. }
  164. }
  165. /**
  166. * ------------------------------------------------------------------------
  167. * jQuery
  168. * ------------------------------------------------------------------------
  169. * add .Popover to jQuery only if jQuery is present
  170. */
  171. defineJQueryPlugin(Popover);
  172. return Popover;
  173. })));
  174. //# sourceMappingURL=popover.js.map