popover.js 6.35 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
31
32
33
34
35
  var JQUERY_NO_CONFLICT = $.fn[NAME];

  var Default = $.extend({}, Tooltip.Default, {
    placement: 'right',
    trigger: 'click',
    content: '',
Mark Otto's avatar
grunt    
Mark Otto committed
36
    template: '<div class="popover" role="tooltip">' + '<h3 class="popover-title"></h3>' + '<div class="popover-content"></div></div>'
fat's avatar
fat committed
37
38
  });

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

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

  var Selector = {
    TITLE: '.popover-title',
Mark Otto's avatar
grunt    
Mark Otto committed
50
    CONTENT: '.popover-content'
fat's avatar
fat committed
51
52
53
  };

  var Event = {
fat's avatar
fat committed
54
55
56
57
58
59
60
61
62
63
    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
64
65
66
67
68
69
70
71
  };

  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */

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

fat's avatar
fat committed
75
76
77
    function Popover() {
      _classCallCheck(this, Popover);

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

Mark Otto's avatar
grunt    
Mark Otto committed
81
    // overrides
fat's avatar
fat committed
82

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

Mark Otto's avatar
grunt    
Mark Otto committed
87
88
89
    Popover.prototype.getTipElement = function getTipElement() {
      return this.tip = this.tip || $(this.config.template)[0];
    };
fat's avatar
fat committed
90

Mark Otto's avatar
grunt    
Mark Otto committed
91
92
    Popover.prototype.setContent = function setContent() {
      var $tip = $(this.getTipElement());
fat's avatar
fat committed
93

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

Mark Otto's avatar
grunt    
Mark Otto committed
98
      $tip.removeClass(ClassName.FADE + ' ' + ClassName.SHOW);
fat's avatar
fat committed
99

Mark Otto's avatar
grunt    
Mark Otto committed
100
101
      this.cleanupTether();
    };
fat's avatar
fat committed
102

Mark Otto's avatar
grunt    
Mark Otto committed
103
    // private
fat's avatar
fat committed
104

Mark Otto's avatar
grunt    
Mark Otto committed
105
106
107
    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
108

Mark Otto's avatar
grunt    
Mark Otto committed
109
    // static
Jacob Thornton's avatar
Jacob Thornton committed
110

Mark Otto's avatar
grunt    
Mark Otto committed
111
112
113
114
    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
115

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
125
126
127
        if (typeof config === 'string') {
          if (data[config] === undefined) {
            throw new Error('No method named "' + config + '"');
Jacob Thornton's avatar
Jacob Thornton committed
128
          }
Mark Otto's avatar
grunt    
Mark Otto committed
129
130
131
132
133
134
          data[config]();
        }
      });
    };

    _createClass(Popover, null, [{
fat's avatar
fat committed
135
136
      key: 'VERSION',

Mark Otto's avatar
grunt    
Mark Otto committed
137

fat's avatar
fat committed
138
139
      // getters

Jacob Thornton's avatar
Jacob Thornton committed
140
      get: function get() {
fat's avatar
fat committed
141
142
143
144
        return VERSION;
      }
    }, {
      key: 'Default',
Jacob Thornton's avatar
Jacob Thornton committed
145
      get: function get() {
fat's avatar
fat committed
146
147
148
149
        return Default;
      }
    }, {
      key: 'NAME',
Jacob Thornton's avatar
Jacob Thornton committed
150
      get: function get() {
fat's avatar
fat committed
151
152
153
154
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
155
      get: function get() {
fat's avatar
fat committed
156
157
158
159
        return DATA_KEY;
      }
    }, {
      key: 'Event',
Jacob Thornton's avatar
Jacob Thornton committed
160
      get: function get() {
fat's avatar
fat committed
161
162
        return Event;
      }
fat's avatar
fat committed
163
164
    }, {
      key: 'EVENT_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
165
      get: function get() {
fat's avatar
fat committed
166
167
        return EVENT_KEY;
      }
fat's avatar
fat committed
168
169
    }, {
      key: 'DefaultType',
Jacob Thornton's avatar
Jacob Thornton committed
170
      get: function get() {
fat's avatar
fat committed
171
172
        return DefaultType;
      }
fat's avatar
fat committed
173
174
175
    }]);

    return Popover;
Mark Otto's avatar
grunt    
Mark Otto committed
176
177
178
179
180
181
182
  }(Tooltip);

  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
183
184
185
186
187
188
189
190
191

  $.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
192
}(jQuery);
Jacob Thornton's avatar
Jacob Thornton committed
193
//# sourceMappingURL=popover.js.map