popover.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*!
  2. * Bootstrap popover.js v4.5.2 (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/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./tooltip.js')) :
  8. typeof define === 'function' && define.amd ? define(['jquery', './tooltip.js'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Popover = factory(global.jQuery, global.Tooltip));
  10. }(this, (function ($, Tooltip) { 'use strict';
  11. $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;
  12. Tooltip = Tooltip && Object.prototype.hasOwnProperty.call(Tooltip, 'default') ? Tooltip['default'] : Tooltip;
  13. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  16. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  17. /**
  18. * ------------------------------------------------------------------------
  19. * Constants
  20. * ------------------------------------------------------------------------
  21. */
  22. var NAME = 'popover';
  23. var VERSION = '4.5.2';
  24. var DATA_KEY = 'bs.popover';
  25. var EVENT_KEY = "." + DATA_KEY;
  26. var JQUERY_NO_CONFLICT = $.fn[NAME];
  27. var CLASS_PREFIX = 'bs-popover';
  28. var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
  29. var Default = _extends({}, Tooltip.Default, {
  30. placement: 'right',
  31. trigger: 'click',
  32. content: '',
  33. template: '<div class="popover" role="tooltip">' + '<div class="arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div></div>'
  34. });
  35. var DefaultType = _extends({}, Tooltip.DefaultType, {
  36. content: '(string|element|function)'
  37. });
  38. var CLASS_NAME_FADE = 'fade';
  39. var CLASS_NAME_SHOW = 'show';
  40. var SELECTOR_TITLE = '.popover-header';
  41. var SELECTOR_CONTENT = '.popover-body';
  42. var Event = {
  43. HIDE: "hide" + EVENT_KEY,
  44. HIDDEN: "hidden" + EVENT_KEY,
  45. SHOW: "show" + EVENT_KEY,
  46. SHOWN: "shown" + EVENT_KEY,
  47. INSERTED: "inserted" + EVENT_KEY,
  48. CLICK: "click" + EVENT_KEY,
  49. FOCUSIN: "focusin" + EVENT_KEY,
  50. FOCUSOUT: "focusout" + EVENT_KEY,
  51. MOUSEENTER: "mouseenter" + EVENT_KEY,
  52. MOUSELEAVE: "mouseleave" + EVENT_KEY
  53. };
  54. /**
  55. * ------------------------------------------------------------------------
  56. * Class Definition
  57. * ------------------------------------------------------------------------
  58. */
  59. var Popover = /*#__PURE__*/function (_Tooltip) {
  60. _inheritsLoose(Popover, _Tooltip);
  61. function Popover() {
  62. return _Tooltip.apply(this, arguments) || this;
  63. }
  64. var _proto = Popover.prototype;
  65. // Overrides
  66. _proto.isWithContent = function isWithContent() {
  67. return this.getTitle() || this._getContent();
  68. };
  69. _proto.addAttachmentClass = function addAttachmentClass(attachment) {
  70. $(this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
  71. };
  72. _proto.getTipElement = function getTipElement() {
  73. this.tip = this.tip || $(this.config.template)[0];
  74. return this.tip;
  75. };
  76. _proto.setContent = function setContent() {
  77. var $tip = $(this.getTipElement()); // We use append for html objects to maintain js events
  78. this.setElementContent($tip.find(SELECTOR_TITLE), this.getTitle());
  79. var content = this._getContent();
  80. if (typeof content === 'function') {
  81. content = content.call(this.element);
  82. }
  83. this.setElementContent($tip.find(SELECTOR_CONTENT), content);
  84. $tip.removeClass(CLASS_NAME_FADE + " " + CLASS_NAME_SHOW);
  85. } // Private
  86. ;
  87. _proto._getContent = function _getContent() {
  88. return this.element.getAttribute('data-content') || this.config.content;
  89. };
  90. _proto._cleanTipClass = function _cleanTipClass() {
  91. var $tip = $(this.getTipElement());
  92. var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);
  93. if (tabClass !== null && tabClass.length > 0) {
  94. $tip.removeClass(tabClass.join(''));
  95. }
  96. } // Static
  97. ;
  98. Popover._jQueryInterface = function _jQueryInterface(config) {
  99. return this.each(function () {
  100. var data = $(this).data(DATA_KEY);
  101. var _config = typeof config === 'object' ? config : null;
  102. if (!data && /dispose|hide/.test(config)) {
  103. return;
  104. }
  105. if (!data) {
  106. data = new Popover(this, _config);
  107. $(this).data(DATA_KEY, data);
  108. }
  109. if (typeof config === 'string') {
  110. if (typeof data[config] === 'undefined') {
  111. throw new TypeError("No method named \"" + config + "\"");
  112. }
  113. data[config]();
  114. }
  115. });
  116. };
  117. _createClass(Popover, null, [{
  118. key: "VERSION",
  119. // Getters
  120. get: function get() {
  121. return VERSION;
  122. }
  123. }, {
  124. key: "Default",
  125. get: function get() {
  126. return Default;
  127. }
  128. }, {
  129. key: "NAME",
  130. get: function get() {
  131. return NAME;
  132. }
  133. }, {
  134. key: "DATA_KEY",
  135. get: function get() {
  136. return DATA_KEY;
  137. }
  138. }, {
  139. key: "Event",
  140. get: function get() {
  141. return Event;
  142. }
  143. }, {
  144. key: "EVENT_KEY",
  145. get: function get() {
  146. return EVENT_KEY;
  147. }
  148. }, {
  149. key: "DefaultType",
  150. get: function get() {
  151. return DefaultType;
  152. }
  153. }]);
  154. return Popover;
  155. }(Tooltip);
  156. /**
  157. * ------------------------------------------------------------------------
  158. * jQuery
  159. * ------------------------------------------------------------------------
  160. */
  161. $.fn[NAME] = Popover._jQueryInterface;
  162. $.fn[NAME].Constructor = Popover;
  163. $.fn[NAME].noConflict = function () {
  164. $.fn[NAME] = JQUERY_NO_CONFLICT;
  165. return Popover._jQueryInterface;
  166. };
  167. return Popover;
  168. })));
  169. //# sourceMappingURL=popover.js.map