popover.js 5.81 KB
Newer Older
Mark Otto's avatar
dist    
Mark Otto committed
1
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); } }
Mark Otto's avatar
dist    
Mark Otto committed
2

Mark Otto's avatar
dist    
Mark Otto committed
3
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
fat's avatar
fat committed
4

Mark Otto's avatar
dist    
Mark Otto committed
5
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
fat's avatar
fat committed
6
7
8

/**
 * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
9
 * Bootstrap (v4.0.0-beta.2): popover.js
fat's avatar
fat committed
10
11
12
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */
Mark Otto's avatar
dist    
Mark Otto committed
13
var Popover = function ($) {
fat's avatar
fat committed
14
15
16
17
18
19
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */
  var NAME = 'popover';
Mark Otto's avatar
Mark Otto committed
20
  var VERSION = '4.0.0-beta.2';
fat's avatar
fat committed
21
  var DATA_KEY = 'bs.popover';
Mark Otto's avatar
dist    
Mark Otto committed
22
  var EVENT_KEY = "." + DATA_KEY;
fat's avatar
fat committed
23
  var JQUERY_NO_CONFLICT = $.fn[NAME];
Johann-S's avatar
build    
Johann-S committed
24
  var CLASS_PREFIX = 'bs-popover';
Mark Otto's avatar
dist    
Mark Otto committed
25
  var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
fat's avatar
fat committed
26
27
28
29
  var Default = $.extend({}, Tooltip.Default, {
    placement: 'right',
    trigger: 'click',
    content: '',
Mark Otto's avatar
Mark Otto committed
30
    template: '<div class="popover" role="tooltip">' + '<div class="arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div></div>'
fat's avatar
fat committed
31
  });
fat's avatar
fat committed
32
  var DefaultType = $.extend({}, Tooltip.DefaultType, {
XhmikosR's avatar
XhmikosR committed
33
    content: '(string|element|function)'
fat's avatar
fat committed
34
  });
fat's avatar
fat committed
35
36
  var ClassName = {
    FADE: 'fade',
Mark Otto's avatar
grunt    
Mark Otto committed
37
    SHOW: 'show'
fat's avatar
fat committed
38
39
  };
  var Selector = {
Mark Otto's avatar
Mark Otto committed
40
41
    TITLE: '.popover-header',
    CONTENT: '.popover-body'
fat's avatar
fat committed
42
43
  };
  var Event = {
Mark Otto's avatar
dist    
Mark Otto committed
44
45
46
47
48
49
50
51
52
53
    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
Mark Otto's avatar
dist    
Mark Otto committed
54
55
56
57
58
    /**
     * ------------------------------------------------------------------------
     * Class Definition
     * ------------------------------------------------------------------------
     */
fat's avatar
fat committed
59

Mark Otto's avatar
dist    
Mark Otto committed
60
  };
Jacob Thornton's avatar
Jacob Thornton committed
61

Mark Otto's avatar
dist    
Mark Otto committed
62
63
64
65
  var Popover =
  /*#__PURE__*/
  function (_Tooltip) {
    _inheritsLoose(Popover, _Tooltip);
fat's avatar
fat committed
66

Mark Otto's avatar
dist    
Mark Otto committed
67
68
    function Popover() {
      return _Tooltip.apply(this, arguments) || this;
fat's avatar
fat committed
69
70
    }

Mark Otto's avatar
dist    
Mark Otto committed
71
    var _proto = Popover.prototype;
Johann-S's avatar
build    
Johann-S committed
72

Mark Otto's avatar
dist    
Mark Otto committed
73
74
75
76
    // overrides
    _proto.isWithContent = function isWithContent() {
      return this.getTitle() || this._getContent();
    };
fat's avatar
fat committed
77

Mark Otto's avatar
dist    
Mark Otto committed
78
79
80
    _proto.addAttachmentClass = function addAttachmentClass(attachment) {
      $(this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
    };
fat's avatar
fat committed
81

Mark Otto's avatar
dist    
Mark Otto committed
82
83
84
85
    _proto.getTipElement = function getTipElement() {
      this.tip = this.tip || $(this.config.template)[0];
      return this.tip;
    };
fat's avatar
fat committed
86

Mark Otto's avatar
dist    
Mark Otto committed
87
88
    _proto.setContent = function setContent() {
      var $tip = $(this.getTipElement()); // we use append for html objects to maintain js events
fat's avatar
fat committed
89

Mark Otto's avatar
dist    
Mark Otto committed
90
91
92
93
      this.setElementContent($tip.find(Selector.TITLE), this.getTitle());
      this.setElementContent($tip.find(Selector.CONTENT), this._getContent());
      $tip.removeClass(ClassName.FADE + " " + ClassName.SHOW);
    }; // private
fat's avatar
fat committed
94

Jacob Thornton's avatar
Jacob Thornton committed
95

Mark Otto's avatar
dist    
Mark Otto committed
96
97
98
99
100
101
102
103
104
105
    _proto._getContent = function _getContent() {
      return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content);
    };

    _proto._cleanTipClass = function _cleanTipClass() {
      var $tip = $(this.getTipElement());
      var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);

      if (tabClass !== null && tabClass.length > 0) {
        $tip.removeClass(tabClass.join(''));
Johann-S's avatar
build    
Johann-S committed
106
      }
Mark Otto's avatar
dist    
Mark Otto committed
107
    }; // static
Jacob Thornton's avatar
Jacob Thornton committed
108
109


Mark Otto's avatar
dist    
Mark Otto committed
110
111
112
    Popover._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
Jacob Thornton's avatar
Jacob Thornton committed
113

Mark Otto's avatar
dist    
Mark Otto committed
114
        var _config = typeof config === 'object' ? config : null;
Jacob Thornton's avatar
Jacob Thornton committed
115

Mark Otto's avatar
dist    
Mark Otto committed
116
117
118
        if (!data && /destroy|hide/.test(config)) {
          return;
        }
Mark Otto's avatar
grunt    
Mark Otto committed
119

Mark Otto's avatar
dist    
Mark Otto committed
120
121
122
123
124
125
126
127
        if (!data) {
          data = new Popover(this, _config);
          $(this).data(DATA_KEY, data);
        }

        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
            throw new Error("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
128
          }
fat's avatar
fat committed
129

Mark Otto's avatar
dist    
Mark Otto committed
130
131
132
133
          data[config]();
        }
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
134

Mark Otto's avatar
dist    
Mark Otto committed
135
136
    _createClass(Popover, null, [{
      key: "VERSION",
fat's avatar
fat committed
137
      // getters
Jacob Thornton's avatar
Jacob Thornton committed
138
      get: function get() {
fat's avatar
fat committed
139
140
141
        return VERSION;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
142
      key: "Default",
Jacob Thornton's avatar
Jacob Thornton committed
143
      get: function get() {
fat's avatar
fat committed
144
145
146
        return Default;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
147
      key: "NAME",
Jacob Thornton's avatar
Jacob Thornton committed
148
      get: function get() {
fat's avatar
fat committed
149
150
151
        return NAME;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
152
      key: "DATA_KEY",
Jacob Thornton's avatar
Jacob Thornton committed
153
      get: function get() {
fat's avatar
fat committed
154
155
156
        return DATA_KEY;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
157
      key: "Event",
Jacob Thornton's avatar
Jacob Thornton committed
158
      get: function get() {
fat's avatar
fat committed
159
160
        return Event;
      }
fat's avatar
fat committed
161
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
162
      key: "EVENT_KEY",
Jacob Thornton's avatar
Jacob Thornton committed
163
      get: function get() {
fat's avatar
fat committed
164
165
        return EVENT_KEY;
      }
fat's avatar
fat committed
166
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
167
      key: "DefaultType",
Jacob Thornton's avatar
Jacob Thornton committed
168
      get: function get() {
fat's avatar
fat committed
169
170
        return DefaultType;
      }
fat's avatar
fat committed
171
172
173
    }]);

    return Popover;
Mark Otto's avatar
grunt    
Mark Otto committed
174
175
176
177
178
179
  }(Tooltip);
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
180

Mark Otto's avatar
dist    
Mark Otto committed
181

fat's avatar
fat committed
182
183
  $.fn[NAME] = Popover._jQueryInterface;
  $.fn[NAME].Constructor = Popover;
Mark Otto's avatar
dist    
Mark Otto committed
184

fat's avatar
fat committed
185
186
187
188
189
190
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Popover._jQueryInterface;
  };

  return Popover;
Mark Otto's avatar
dist    
Mark Otto committed
191
}($);
Mark Otto's avatar
build    
Mark Otto committed
192
//# sourceMappingURL=popover.js.map