popover.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*!
  2. * Bootstrap popover.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('./tooltip.js')) :
  8. typeof define === 'function' && define.amd ? define(['jquery', './tooltip.js'], factory) :
  9. (global = global || self, global.Popover = factory(global.jQuery, global.Tooltip));
  10. }(this, (function ($, Tooltip) { 'use strict';
  11. $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  12. Tooltip = Tooltip && Tooltip.hasOwnProperty('default') ? Tooltip['default'] : Tooltip;
  13. function _defineProperties(target, props) {
  14. for (var i = 0; i < props.length; i++) {
  15. var descriptor = props[i];
  16. descriptor.enumerable = descriptor.enumerable || false;
  17. descriptor.configurable = true;
  18. if ("value" in descriptor) descriptor.writable = true;
  19. Object.defineProperty(target, descriptor.key, descriptor);
  20. }
  21. }
  22. function _createClass(Constructor, protoProps, staticProps) {
  23. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  24. if (staticProps) _defineProperties(Constructor, staticProps);
  25. return Constructor;
  26. }
  27. function _defineProperty(obj, key, value) {
  28. if (key in obj) {
  29. Object.defineProperty(obj, key, {
  30. value: value,
  31. enumerable: true,
  32. configurable: true,
  33. writable: true
  34. });
  35. } else {
  36. obj[key] = value;
  37. }
  38. return obj;
  39. }
  40. function ownKeys(object, enumerableOnly) {
  41. var keys = Object.keys(object);
  42. if (Object.getOwnPropertySymbols) {
  43. var symbols = Object.getOwnPropertySymbols(object);
  44. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  45. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  46. });
  47. keys.push.apply(keys, symbols);
  48. }
  49. return keys;
  50. }
  51. function _objectSpread2(target) {
  52. for (var i = 1; i < arguments.length; i++) {
  53. var source = arguments[i] != null ? arguments[i] : {};
  54. if (i % 2) {
  55. ownKeys(Object(source), true).forEach(function (key) {
  56. _defineProperty(target, key, source[key]);
  57. });
  58. } else if (Object.getOwnPropertyDescriptors) {
  59. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  60. } else {
  61. ownKeys(Object(source)).forEach(function (key) {
  62. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  63. });
  64. }
  65. }
  66. return target;
  67. }
  68. function _inheritsLoose(subClass, superClass) {
  69. subClass.prototype = Object.create(superClass.prototype);
  70. subClass.prototype.constructor = subClass;
  71. subClass.__proto__ = superClass;
  72. }
  73. /**
  74. * ------------------------------------------------------------------------
  75. * Constants
  76. * ------------------------------------------------------------------------
  77. */
  78. var NAME = 'popover';
  79. var VERSION = '4.4.1';
  80. var DATA_KEY = 'bs.popover';
  81. var EVENT_KEY = "." + DATA_KEY;
  82. var JQUERY_NO_CONFLICT = $.fn[NAME];
  83. var CLASS_PREFIX = 'bs-popover';
  84. var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
  85. var Default = _objectSpread2({}, Tooltip.Default, {
  86. placement: 'right',
  87. trigger: 'click',
  88. content: '',
  89. template: '<div class="popover" role="tooltip">' + '<div class="arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div></div>'
  90. });
  91. var DefaultType = _objectSpread2({}, Tooltip.DefaultType, {
  92. content: '(string|element|function)'
  93. });
  94. var ClassName = {
  95. FADE: 'fade',
  96. SHOW: 'show'
  97. };
  98. var Selector = {
  99. TITLE: '.popover-header',
  100. CONTENT: '.popover-body'
  101. };
  102. var Event = {
  103. HIDE: "hide" + EVENT_KEY,
  104. HIDDEN: "hidden" + EVENT_KEY,
  105. SHOW: "show" + EVENT_KEY,
  106. SHOWN: "shown" + EVENT_KEY,
  107. INSERTED: "inserted" + EVENT_KEY,
  108. CLICK: "click" + EVENT_KEY,
  109. FOCUSIN: "focusin" + EVENT_KEY,
  110. FOCUSOUT: "focusout" + EVENT_KEY,
  111. MOUSEENTER: "mouseenter" + EVENT_KEY,
  112. MOUSELEAVE: "mouseleave" + EVENT_KEY
  113. };
  114. /**
  115. * ------------------------------------------------------------------------
  116. * Class Definition
  117. * ------------------------------------------------------------------------
  118. */
  119. var Popover =
  120. /*#__PURE__*/
  121. function (_Tooltip) {
  122. _inheritsLoose(Popover, _Tooltip);
  123. function Popover() {
  124. return _Tooltip.apply(this, arguments) || this;
  125. }
  126. var _proto = Popover.prototype;
  127. // Overrides
  128. _proto.isWithContent = function isWithContent() {
  129. return this.getTitle() || this._getContent();
  130. };
  131. _proto.addAttachmentClass = function addAttachmentClass(attachment) {
  132. $(this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
  133. };
  134. _proto.getTipElement = function getTipElement() {
  135. this.tip = this.tip || $(this.config.template)[0];
  136. return this.tip;
  137. };
  138. _proto.setContent = function setContent() {
  139. var $tip = $(this.getTipElement()); // We use append for html objects to maintain js events
  140. this.setElementContent($tip.find(Selector.TITLE), this.getTitle());
  141. var content = this._getContent();
  142. if (typeof content === 'function') {
  143. content = content.call(this.element);
  144. }
  145. this.setElementContent($tip.find(Selector.CONTENT), content);
  146. $tip.removeClass(ClassName.FADE + " " + ClassName.SHOW);
  147. } // Private
  148. ;
  149. _proto._getContent = function _getContent() {
  150. return this.element.getAttribute('data-content') || this.config.content;
  151. };
  152. _proto._cleanTipClass = function _cleanTipClass() {
  153. var $tip = $(this.getTipElement());
  154. var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);
  155. if (tabClass !== null && tabClass.length > 0) {
  156. $tip.removeClass(tabClass.join(''));
  157. }
  158. } // Static
  159. ;
  160. Popover._jQueryInterface = function _jQueryInterface(config) {
  161. return this.each(function () {
  162. var data = $(this).data(DATA_KEY);
  163. var _config = typeof config === 'object' ? config : null;
  164. if (!data && /dispose|hide/.test(config)) {
  165. return;
  166. }
  167. if (!data) {
  168. data = new Popover(this, _config);
  169. $(this).data(DATA_KEY, data);
  170. }
  171. if (typeof config === 'string') {
  172. if (typeof data[config] === 'undefined') {
  173. throw new TypeError("No method named \"" + config + "\"");
  174. }
  175. data[config]();
  176. }
  177. });
  178. };
  179. _createClass(Popover, null, [{
  180. key: "VERSION",
  181. // Getters
  182. get: function get() {
  183. return VERSION;
  184. }
  185. }, {
  186. key: "Default",
  187. get: function get() {
  188. return Default;
  189. }
  190. }, {
  191. key: "NAME",
  192. get: function get() {
  193. return NAME;
  194. }
  195. }, {
  196. key: "DATA_KEY",
  197. get: function get() {
  198. return DATA_KEY;
  199. }
  200. }, {
  201. key: "Event",
  202. get: function get() {
  203. return Event;
  204. }
  205. }, {
  206. key: "EVENT_KEY",
  207. get: function get() {
  208. return EVENT_KEY;
  209. }
  210. }, {
  211. key: "DefaultType",
  212. get: function get() {
  213. return DefaultType;
  214. }
  215. }]);
  216. return Popover;
  217. }(Tooltip);
  218. /**
  219. * ------------------------------------------------------------------------
  220. * jQuery
  221. * ------------------------------------------------------------------------
  222. */
  223. $.fn[NAME] = Popover._jQueryInterface;
  224. $.fn[NAME].Constructor = Popover;
  225. $.fn[NAME].noConflict = function () {
  226. $.fn[NAME] = JQUERY_NO_CONFLICT;
  227. return Popover._jQueryInterface;
  228. };
  229. return Popover;
  230. })));
  231. //# sourceMappingURL=popover.js.map