popover.js 6.91 KB
Newer Older
Mark Otto's avatar
grunt    
Mark Otto committed
1
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
fat's avatar
fat committed
2

Mark Otto's avatar
grunt    
Mark Otto committed
3
var _createClass = function () { 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); } } return function (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
grunt    
Mark Otto committed
5
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Jacob Thornton's avatar
Jacob Thornton committed
6

Mark Otto's avatar
grunt    
Mark Otto committed
7
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
fat's avatar
fat committed
8

Mark Otto's avatar
grunt    
Mark Otto committed
9
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
fat's avatar
fat committed
10
11
12

/**
 * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
13
 * Bootstrap (v4.0.0-alpha.6): popover.js
fat's avatar
fat committed
14
15
16
17
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */

Mark Otto's avatar
grunt    
Mark Otto committed
18
var Popover = function ($) {
fat's avatar
fat committed
19
20
21
22
23
24
25
26

  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'popover';
Mark Otto's avatar
Mark Otto committed
27
  var VERSION = '4.0.0-alpha.6';
fat's avatar
fat committed
28
  var DATA_KEY = 'bs.popover';
fat's avatar
fat committed
29
  var EVENT_KEY = '.' + DATA_KEY;
fat's avatar
fat committed
30
  var JQUERY_NO_CONFLICT = $.fn[NAME];
Johann-S's avatar
build    
Johann-S committed
31
32
  var CLASS_PREFIX = 'bs-popover';
  var BSCLS_PREFIX_REGEX = new RegExp('(^|\\s)' + CLASS_PREFIX + '\\S+', 'g');
fat's avatar
fat committed
33
34
35
36
37

  var Default = $.extend({}, Tooltip.Default, {
    placement: 'right',
    trigger: 'click',
    content: '',
Mark Otto's avatar
Mark Otto committed
38
    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
39
40
  });

fat's avatar
fat committed
41
  var DefaultType = $.extend({}, Tooltip.DefaultType, {
XhmikosR's avatar
XhmikosR committed
42
    content: '(string|element|function)'
fat's avatar
fat committed
43
44
  });

fat's avatar
fat committed
45
46
  var ClassName = {
    FADE: 'fade',
Mark Otto's avatar
grunt    
Mark Otto committed
47
    SHOW: 'show'
fat's avatar
fat committed
48
49
50
  };

  var Selector = {
Mark Otto's avatar
Mark Otto committed
51
52
    TITLE: '.popover-header',
    CONTENT: '.popover-body'
fat's avatar
fat committed
53
54
55
  };

  var Event = {
fat's avatar
fat committed
56
57
58
59
60
61
62
63
64
65
    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
fat's avatar
fat committed
66

Mark Otto's avatar
dist    
Mark Otto committed
67
68
69
70
71
    /**
     * ------------------------------------------------------------------------
     * Class Definition
     * ------------------------------------------------------------------------
     */
fat's avatar
fat committed
72

Mark Otto's avatar
dist    
Mark Otto committed
73
  };
Mark Otto's avatar
grunt    
Mark Otto committed
74
  var Popover = function (_Tooltip) {
Jacob Thornton's avatar
Jacob Thornton committed
75
76
    _inherits(Popover, _Tooltip);

fat's avatar
fat committed
77
78
79
    function Popover() {
      _classCallCheck(this, Popover);

Mark Otto's avatar
grunt    
Mark Otto committed
80
      return _possibleConstructorReturn(this, _Tooltip.apply(this, arguments));
fat's avatar
fat committed
81
82
    }

Mark Otto's avatar
grunt    
Mark Otto committed
83
    // overrides
fat's avatar
fat committed
84

Mark Otto's avatar
grunt    
Mark Otto committed
85
86
87
    Popover.prototype.isWithContent = function isWithContent() {
      return this.getTitle() || this._getContent();
    };
fat's avatar
fat committed
88

Johann-S's avatar
build    
Johann-S committed
89
90
91
92
    Popover.prototype.addAttachmentClass = function addAttachmentClass(attachment) {
      $(this.getTipElement()).addClass(CLASS_PREFIX + '-' + attachment);
    };

Mark Otto's avatar
grunt    
Mark Otto committed
93
94
95
    Popover.prototype.getTipElement = function getTipElement() {
      return this.tip = this.tip || $(this.config.template)[0];
    };
fat's avatar
fat committed
96

Mark Otto's avatar
grunt    
Mark Otto committed
97
    Popover.prototype.setContent = function setContent() {
Mark Otto's avatar
Mark Otto committed
98
      var $tip = $(this.getTipElement());
fat's avatar
fat committed
99

Mark Otto's avatar
grunt    
Mark Otto committed
100
      // we use append for html objects to maintain js events
Mark Otto's avatar
Mark Otto committed
101
      this.setElementContent($tip.find(Selector.TITLE), this.getTitle());
Mark Otto's avatar
grunt    
Mark Otto committed
102
      this.setElementContent($tip.find(Selector.CONTENT), this._getContent());
fat's avatar
fat committed
103

Mark Otto's avatar
grunt    
Mark Otto committed
104
      $tip.removeClass(ClassName.FADE + ' ' + ClassName.SHOW);
Mark Otto's avatar
grunt    
Mark Otto committed
105
    };
fat's avatar
fat committed
106

Mark Otto's avatar
grunt    
Mark Otto committed
107
    // private
fat's avatar
fat committed
108

Mark Otto's avatar
grunt    
Mark Otto committed
109
110
111
    Popover.prototype._getContent = function _getContent() {
      return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content);
    };
Jacob Thornton's avatar
Jacob Thornton committed
112

Johann-S's avatar
build    
Johann-S committed
113
114
115
116
117
118
119
120
    Popover.prototype._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(''));
      }
    };

Mark Otto's avatar
grunt    
Mark Otto committed
121
    // static
Jacob Thornton's avatar
Jacob Thornton committed
122

Mark Otto's avatar
grunt    
Mark Otto committed
123
124
125
126
    Popover._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
        var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' ? config : null;
Jacob Thornton's avatar
Jacob Thornton committed
127

Mark Otto's avatar
grunt    
Mark Otto committed
128
129
130
        if (!data && /destroy|hide/.test(config)) {
          return;
        }
Jacob Thornton's avatar
Jacob Thornton committed
131

Mark Otto's avatar
grunt    
Mark Otto committed
132
133
134
135
        if (!data) {
          data = new Popover(this, _config);
          $(this).data(DATA_KEY, data);
        }
Jacob Thornton's avatar
Jacob Thornton committed
136

Mark Otto's avatar
grunt    
Mark Otto committed
137
138
139
        if (typeof config === 'string') {
          if (data[config] === undefined) {
            throw new Error('No method named "' + config + '"');
Jacob Thornton's avatar
Jacob Thornton committed
140
          }
Mark Otto's avatar
grunt    
Mark Otto committed
141
142
143
144
145
146
          data[config]();
        }
      });
    };

    _createClass(Popover, null, [{
fat's avatar
fat committed
147
148
      key: 'VERSION',

Mark Otto's avatar
grunt    
Mark Otto committed
149

fat's avatar
fat committed
150
151
      // getters

Jacob Thornton's avatar
Jacob Thornton committed
152
      get: function get() {
fat's avatar
fat committed
153
154
155
156
        return VERSION;
      }
    }, {
      key: 'Default',
Jacob Thornton's avatar
Jacob Thornton committed
157
      get: function get() {
fat's avatar
fat committed
158
159
160
161
        return Default;
      }
    }, {
      key: 'NAME',
Jacob Thornton's avatar
Jacob Thornton committed
162
      get: function get() {
fat's avatar
fat committed
163
164
165
166
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
167
      get: function get() {
fat's avatar
fat committed
168
169
170
171
        return DATA_KEY;
      }
    }, {
      key: 'Event',
Jacob Thornton's avatar
Jacob Thornton committed
172
      get: function get() {
fat's avatar
fat committed
173
174
        return Event;
      }
fat's avatar
fat committed
175
176
    }, {
      key: 'EVENT_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
177
      get: function get() {
fat's avatar
fat committed
178
179
        return EVENT_KEY;
      }
fat's avatar
fat committed
180
181
    }, {
      key: 'DefaultType',
Jacob Thornton's avatar
Jacob Thornton committed
182
      get: function get() {
fat's avatar
fat committed
183
184
        return DefaultType;
      }
fat's avatar
fat committed
185
186
187
    }]);

    return Popover;
Mark Otto's avatar
grunt    
Mark Otto committed
188
189
190
191
192
193
194
  }(Tooltip);

  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
195
196
197
198
199
200
201
202
203

  $.fn[NAME] = Popover._jQueryInterface;
  $.fn[NAME].Constructor = Popover;
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Popover._jQueryInterface;
  };

  return Popover;
Mark Otto's avatar
grunt    
Mark Otto committed
204
}(jQuery);
Mark Otto's avatar
build    
Mark Otto committed
205
//# sourceMappingURL=popover.js.map