0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00
Bootstrap/js/dist/popover.js

194 lines
6.4 KiB
JavaScript
Raw Normal View History

2016-10-10 02:26:51 +02:00
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; };
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
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; }; }();
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2015-08-13 06:12:03 +02:00
2016-10-10 02:26:51 +02:00
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; }
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
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; }
2015-05-12 23:28:11 +02:00
/**
* --------------------------------------------------------------------------
2016-10-19 17:27:41 +02:00
* Bootstrap (v4.0.0-alpha.5): popover.js
2015-05-12 23:28:11 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
2016-10-10 02:26:51 +02:00
var Popover = function ($) {
2015-05-12 23:28:11 +02:00
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'popover';
2016-10-19 17:27:41 +02:00
var VERSION = '4.0.0-alpha.5';
2015-05-12 23:28:11 +02:00
var DATA_KEY = 'bs.popover';
2015-05-13 21:48:34 +02:00
var EVENT_KEY = '.' + DATA_KEY;
2015-05-12 23:28:11 +02:00
var JQUERY_NO_CONFLICT = $.fn[NAME];
var Default = $.extend({}, Tooltip.Default, {
placement: 'right',
trigger: 'click',
content: '',
2016-10-10 05:26:49 +02:00
template: '<div class="popover" role="tooltip">' + '<h3 class="popover-title"></h3>' + '<div class="popover-content"></div></div>'
2015-05-12 23:28:11 +02:00
});
2015-05-13 23:46:50 +02:00
var DefaultType = $.extend({}, Tooltip.DefaultType, {
2015-08-29 23:03:55 +02:00
content: '(string|element|function)'
2015-05-13 23:46:50 +02:00
});
2015-05-12 23:28:11 +02:00
var ClassName = {
FADE: 'fade',
2016-12-20 06:48:24 +01:00
SHOW: 'show'
2015-05-12 23:28:11 +02:00
};
var Selector = {
TITLE: '.popover-title',
2016-10-10 05:26:49 +02:00
CONTENT: '.popover-content'
2015-05-12 23:28:11 +02:00
};
var Event = {
2015-05-13 21:48:34 +02:00
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
2015-05-12 23:28:11 +02:00
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
2016-10-10 02:26:51 +02:00
var Popover = function (_Tooltip) {
2015-08-13 06:12:03 +02:00
_inherits(Popover, _Tooltip);
2015-05-12 23:28:11 +02:00
function Popover() {
_classCallCheck(this, Popover);
2016-10-10 02:26:51 +02:00
return _possibleConstructorReturn(this, _Tooltip.apply(this, arguments));
2015-05-12 23:28:11 +02:00
}
2016-10-10 02:26:51 +02:00
// overrides
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
Popover.prototype.isWithContent = function isWithContent() {
return this.getTitle() || this._getContent();
};
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
Popover.prototype.getTipElement = function getTipElement() {
return this.tip = this.tip || $(this.config.template)[0];
};
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
Popover.prototype.setContent = function setContent() {
var $tip = $(this.getTipElement());
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
// 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());
2015-05-12 23:28:11 +02:00
2016-12-20 06:48:24 +01:00
$tip.removeClass(ClassName.FADE + ' ' + ClassName.SHOW);
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
this.cleanupTether();
};
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
// private
2015-05-12 23:28:11 +02:00
2016-10-10 02:26:51 +02:00
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);
};
2015-08-13 06:12:03 +02:00
2016-10-10 02:26:51 +02:00
// static
2015-08-13 06:12:03 +02:00
2016-10-10 02:26:51 +02:00
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;
2015-08-13 06:12:03 +02:00
2016-10-10 02:26:51 +02:00
if (!data && /destroy|hide/.test(config)) {
return;
}
2015-08-13 06:12:03 +02:00
2016-10-10 02:26:51 +02:00
if (!data) {
data = new Popover(this, _config);
$(this).data(DATA_KEY, data);
}
2015-08-13 06:12:03 +02:00
2016-10-10 02:26:51 +02:00
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
2015-08-13 06:12:03 +02:00
}
2016-10-10 02:26:51 +02:00
data[config]();
}
});
};
_createClass(Popover, null, [{
2015-05-12 23:28:11 +02:00
key: 'VERSION',
2016-10-10 02:26:51 +02:00
2015-05-12 23:28:11 +02:00
// getters
2015-08-13 06:12:03 +02:00
get: function get() {
2015-05-12 23:28:11 +02:00
return VERSION;
}
}, {
key: 'Default',
2015-08-13 06:12:03 +02:00
get: function get() {
2015-05-12 23:28:11 +02:00
return Default;
}
}, {
key: 'NAME',
2015-08-13 06:12:03 +02:00
get: function get() {
2015-05-12 23:28:11 +02:00
return NAME;
}
}, {
key: 'DATA_KEY',
2015-08-13 06:12:03 +02:00
get: function get() {
2015-05-12 23:28:11 +02:00
return DATA_KEY;
}
}, {
key: 'Event',
2015-08-13 06:12:03 +02:00
get: function get() {
2015-05-12 23:28:11 +02:00
return Event;
}
2015-05-13 21:48:34 +02:00
}, {
key: 'EVENT_KEY',
2015-08-13 06:12:03 +02:00
get: function get() {
2015-05-13 21:48:34 +02:00
return EVENT_KEY;
}
2015-05-13 23:46:50 +02:00
}, {
key: 'DefaultType',
2015-08-13 06:12:03 +02:00
get: function get() {
2015-05-13 23:46:50 +02:00
return DefaultType;
}
2015-05-12 23:28:11 +02:00
}]);
return Popover;
2016-10-10 02:26:51 +02:00
}(Tooltip);
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
2015-05-12 23:28:11 +02:00
$.fn[NAME] = Popover._jQueryInterface;
$.fn[NAME].Constructor = Popover;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Popover._jQueryInterface;
};
return Popover;
2016-10-10 02:26:51 +02:00
}(jQuery);
2015-08-13 06:12:03 +02:00
//# sourceMappingURL=popover.js.map