popover.js 8.21 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap popover.js v5.0.0-alpha3 (https://getbootstrap.com/)
XhmikosR's avatar
XhmikosR committed
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
XhmikosR committed
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
Dist    
XhmikosR committed
5
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
XhmikosR's avatar
XhmikosR committed
7
8
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/selector-engine.js'), require('./tooltip.js')) :
  typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/selector-engine.js', './tooltip.js'], factory) :
XhmikosR's avatar
XhmikosR committed
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Popover = factory(global.Data, global.SelectorEngine, global.Tooltip));
XhmikosR's avatar
XhmikosR committed
10
}(this, (function (Data, SelectorEngine, Tooltip) { 'use strict';
Mark Otto's avatar
dist    
Mark Otto committed
11

XhmikosR's avatar
XhmikosR committed
12
13
14
15
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

  var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
  var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
  var Tooltip__default = /*#__PURE__*/_interopDefaultLegacy(Tooltip);
Mark Otto's avatar
dist    
Mark Otto committed
17

XhmikosR's avatar
XhmikosR committed
18
19
  /**
   * --------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
20
   * Bootstrap (v5.0.0-alpha3): util/index.js
XhmikosR's avatar
XhmikosR committed
21
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
XhmikosR committed
22
23
   * --------------------------------------------------------------------------
   */
XhmikosR's avatar
XhmikosR committed
24
25
26
27
28

  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

XhmikosR's avatar
XhmikosR committed
29
    if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
XhmikosR's avatar
XhmikosR committed
30
31
32
33
34
      return jQuery;
    }

    return null;
  };
XhmikosR's avatar
XhmikosR committed
35

XhmikosR's avatar
XhmikosR committed
36
37
38
39
40
41
42
43
  var onDOMContentLoaded = function onDOMContentLoaded(callback) {
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', callback);
    } else {
      callback();
    }
  };

Mark Otto's avatar
Mark Otto committed
44
45
46
47
48
49
  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); } }

  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

XhmikosR's avatar
XhmikosR committed
50
  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); }
XhmikosR's avatar
Dist    
XhmikosR committed
51
52
53
54
55
56
57
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'popover';
XhmikosR's avatar
XhmikosR committed
58
  var VERSION = '5.0.0-alpha3';
XhmikosR's avatar
Dist    
XhmikosR committed
59
60
61
62
63
  var DATA_KEY = 'bs.popover';
  var EVENT_KEY = "." + DATA_KEY;
  var CLASS_PREFIX = 'bs-popover';
  var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');

XhmikosR's avatar
XhmikosR committed
64
  var Default = _extends({}, Tooltip__default['default'].Default, {
XhmikosR's avatar
Dist    
XhmikosR committed
65
66
67
    placement: 'right',
    trigger: 'click',
    content: '',
XhmikosR's avatar
XhmikosR committed
68
    template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div></div>'
XhmikosR's avatar
Dist    
XhmikosR committed
69
70
  });

XhmikosR's avatar
XhmikosR committed
71
  var DefaultType = _extends({}, Tooltip__default['default'].DefaultType, {
XhmikosR's avatar
Dist    
XhmikosR committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    content: '(string|element|function)'
  });

  var Event = {
    HIDE: "hide" + EVENT_KEY,
    HIDDEN: "hidden" + EVENT_KEY,
    SHOW: "show" + EVENT_KEY,
    SHOWN: "shown" + EVENT_KEY,
    INSERTED: "inserted" + EVENT_KEY,
    CLICK: "click" + EVENT_KEY,
    FOCUSIN: "focusin" + EVENT_KEY,
    FOCUSOUT: "focusout" + EVENT_KEY,
    MOUSEENTER: "mouseenter" + EVENT_KEY,
    MOUSELEAVE: "mouseleave" + EVENT_KEY
  };
XhmikosR's avatar
XhmikosR committed
87
88
89
90
  var CLASS_NAME_FADE = 'fade';
  var CLASS_NAME_SHOW = 'show';
  var SELECTOR_TITLE = '.popover-header';
  var SELECTOR_CONTENT = '.popover-body';
XhmikosR's avatar
XhmikosR committed
91
92
93
94
95
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
96

XhmikosR's avatar
XhmikosR committed
97
  var Popover = /*#__PURE__*/function (_Tooltip) {
XhmikosR's avatar
Dist    
XhmikosR committed
98
    _inheritsLoose(Popover, _Tooltip);
fat's avatar
fat committed
99

XhmikosR's avatar
Dist    
XhmikosR committed
100
101
102
    function Popover() {
      return _Tooltip.apply(this, arguments) || this;
    }
Johann-S's avatar
build    
Johann-S committed
103

XhmikosR's avatar
Dist    
XhmikosR committed
104
    var _proto = Popover.prototype;
fat's avatar
fat committed
105

XhmikosR's avatar
Dist    
XhmikosR committed
106
107
108
109
    // Overrides
    _proto.isWithContent = function isWithContent() {
      return this.getTitle() || this._getContent();
    };
fat's avatar
fat committed
110

XhmikosR's avatar
Dist    
XhmikosR committed
111
    _proto.setContent = function setContent() {
XhmikosR's avatar
XhmikosR committed
112
      var tip = this.getTipElement(); // we use append for html objects to maintain js events
Mark Otto's avatar
Mark Otto committed
113

XhmikosR's avatar
XhmikosR committed
114
      this.setElementContent(SelectorEngine__default['default'].findOne(SELECTOR_TITLE, tip), this.getTitle());
Mark Otto's avatar
Mark Otto committed
115

XhmikosR's avatar
Dist    
XhmikosR committed
116
      var content = this._getContent();
Mark Otto's avatar
Mark Otto committed
117

XhmikosR's avatar
Dist    
XhmikosR committed
118
119
120
      if (typeof content === 'function') {
        content = content.call(this.element);
      }
Jacob Thornton's avatar
Jacob Thornton committed
121

XhmikosR's avatar
XhmikosR committed
122
      this.setElementContent(SelectorEngine__default['default'].findOne(SELECTOR_CONTENT, tip), content);
XhmikosR's avatar
XhmikosR committed
123
      tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW);
XhmikosR's avatar
XhmikosR committed
124
125
    } // Private
    ;
XhmikosR's avatar
XhmikosR committed
126
127
128

    _proto._addAttachmentClass = function _addAttachmentClass(attachment) {
      this.getTipElement().classList.add(CLASS_PREFIX + "-" + attachment);
XhmikosR's avatar
XhmikosR committed
129
    };
Mark Otto's avatar
dist    
Mark Otto committed
130

XhmikosR's avatar
Dist    
XhmikosR committed
131
    _proto._getContent = function _getContent() {
XhmikosR's avatar
XhmikosR committed
132
      return this.element.getAttribute('data-bs-content') || this.config.content;
XhmikosR's avatar
Dist    
XhmikosR committed
133
    };
Jacob Thornton's avatar
Jacob Thornton committed
134

XhmikosR's avatar
Dist    
XhmikosR committed
135
    _proto._cleanTipClass = function _cleanTipClass() {
XhmikosR's avatar
XhmikosR committed
136
137
      var tip = this.getTipElement();
      var tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX);
Jacob Thornton's avatar
Jacob Thornton committed
138

XhmikosR's avatar
Dist    
XhmikosR committed
139
      if (tabClass !== null && tabClass.length > 0) {
XhmikosR's avatar
XhmikosR committed
140
141
142
143
144
        tabClass.map(function (token) {
          return token.trim();
        }).forEach(function (tClass) {
          return tip.classList.remove(tClass);
        });
XhmikosR's avatar
Dist    
XhmikosR committed
145
      }
Mark Otto's avatar
Mark Otto committed
146
147
    } // Static
    ;
Jacob Thornton's avatar
Jacob Thornton committed
148

XhmikosR's avatar
XhmikosR committed
149
    Popover.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
Dist    
XhmikosR committed
150
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
151
        var data = Data__default['default'].getData(this, DATA_KEY);
Mark Otto's avatar
grunt    
Mark Otto committed
152

XhmikosR's avatar
Dist    
XhmikosR committed
153
        var _config = typeof config === 'object' ? config : null;
Mark Otto's avatar
dist    
Mark Otto committed
154

XhmikosR's avatar
Dist    
XhmikosR committed
155
156
157
        if (!data && /dispose|hide/.test(config)) {
          return;
        }
fat's avatar
fat committed
158

XhmikosR's avatar
Dist    
XhmikosR committed
159
160
        if (!data) {
          data = new Popover(this, _config);
XhmikosR's avatar
XhmikosR committed
161
          Data__default['default'].setData(this, DATA_KEY, data);
XhmikosR's avatar
Dist    
XhmikosR committed
162
        }
Mark Otto's avatar
dist    
Mark Otto committed
163

XhmikosR's avatar
Dist    
XhmikosR committed
164
165
166
        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
            throw new TypeError("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
167
          }
XhmikosR's avatar
Dist    
XhmikosR committed
168
169

          data[config]();
Mark Otto's avatar
dist    
Mark Otto committed
170
        }
XhmikosR's avatar
Dist    
XhmikosR committed
171
172
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
173

XhmikosR's avatar
XhmikosR committed
174
    Popover.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
175
      return Data__default['default'].getData(element, DATA_KEY);
XhmikosR's avatar
XhmikosR committed
176
177
    };

XhmikosR's avatar
Dist    
XhmikosR committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
    _createClass(Popover, null, [{
      key: "VERSION",
      // Getters
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }, {
      key: "NAME",
      get: function get() {
        return NAME;
      }
    }, {
      key: "DATA_KEY",
      get: function get() {
        return DATA_KEY;
      }
    }, {
      key: "Event",
      get: function get() {
        return Event;
      }
    }, {
      key: "EVENT_KEY",
      get: function get() {
        return EVENT_KEY;
      }
    }, {
      key: "DefaultType",
      get: function get() {
        return DefaultType;
      }
    }]);
fat's avatar
fat committed
215

XhmikosR's avatar
Dist    
XhmikosR committed
216
    return Popover;
XhmikosR's avatar
XhmikosR committed
217
  }(Tooltip__default['default']);
XhmikosR's avatar
Dist    
XhmikosR committed
218
219
220
221
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
222
   * add .Popover to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
223
   */
fat's avatar
fat committed
224

225

XhmikosR's avatar
XhmikosR committed
226
227
228
  onDOMContentLoaded(function () {
    var $ = getjQuery();
    /* istanbul ignore if */
Mark Otto's avatar
dist    
Mark Otto committed
229

XhmikosR's avatar
XhmikosR committed
230
231
232
233
234
235
236
237
238
239
240
    if ($) {
      var JQUERY_NO_CONFLICT = $.fn[NAME];
      $.fn[NAME] = Popover.jQueryInterface;
      $.fn[NAME].Constructor = Popover;

      $.fn[NAME].noConflict = function () {
        $.fn[NAME] = JQUERY_NO_CONFLICT;
        return Popover.jQueryInterface;
      };
    }
  });
fat's avatar
fat committed
241
242

  return Popover;
Mark Otto's avatar
dist    
Mark Otto committed
243

XhmikosR's avatar
XhmikosR committed
244
})));
Mark Otto's avatar
dist    
Mark Otto committed
245
//# sourceMappingURL=popover.js.map