popover.js 7.2 KB

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