UNPKG

bootstrap-vue

Version:

BootstrapVue provides one of the most comprehensive implementations of Bootstrap 4 components and grid system for Vue.js and with extensive and automated WAI-ARIA accessibility markup.

148 lines (123 loc) 5.71 kB
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; }; 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; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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; } 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; } import ToolTip from './tooltip.class'; import { assign } from './object'; import { select, addClass, removeClass, getAttr } from './dom'; var NAME = 'popover'; var CLASS_PREFIX = 'bs-popover'; var BSCLS_PREFIX_REGEX = new RegExp('\\b' + CLASS_PREFIX + '\\S+', 'g'); var Defaults = assign({}, ToolTip.Default, { placement: 'right', trigger: 'click', content: '', template: '<div class="popover" role="tooltip">' + '<div class="arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div></div>' }); var ClassName = { FADE: 'fade', SHOW: 'show' }; var Selector = { TITLE: '.popover-header', CONTENT: '.popover-body' /* istanbul ignore next: dificult to test in Jest/JSDOM environment */ }; var PopOver = function (_ToolTip) { _inherits(PopOver, _ToolTip); function PopOver() { _classCallCheck(this, PopOver); return _possibleConstructorReturn(this, (PopOver.__proto__ || Object.getPrototypeOf(PopOver)).apply(this, arguments)); } _createClass(PopOver, [{ key: 'isWithContent', // Method overrides value: function isWithContent(tip) { tip = tip || this.$tip; if (!tip) { return false; } var hasTitle = Boolean((select(Selector.TITLE, tip) || {}).innerHTML); var hasContent = Boolean((select(Selector.CONTENT, tip) || {}).innerHTML); return hasTitle || hasContent; } }, { key: 'addAttachmentClass', value: function addAttachmentClass(attachment) { addClass(this.getTipElement(), CLASS_PREFIX + '-' + attachment); } }, { key: 'setContent', value: function setContent(tip) { // we use append for html objects to maintain js events/components this.setElementContent(select(Selector.TITLE, tip), this.getTitle()); this.setElementContent(select(Selector.CONTENT, tip), this.getContent()); removeClass(tip, ClassName.FADE); removeClass(tip, ClassName.SHOW); } // This method may look identical to ToolTip version, but it uses a different RegEx defined above }, { key: 'cleanTipClass', value: function cleanTipClass() { var tip = this.getTipElement(); var tabClass = tip.className.match(BSCLS_PREFIX_REGEX); if (tabClass !== null && tabClass.length > 0) { tabClass.forEach(function (cls) { removeClass(tip, cls); }); } } }, { key: 'getTitle', value: function getTitle() { var title = this.$config.title || ''; if (typeof title === 'function') { title = title(this.$element); } if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object' && title.nodeType && !title.innerHTML.trim()) { // We have a dom node, but without inner content, so just return an empty string title = ''; } if (typeof title === 'string') { title = title.trim(); } if (!title) { // Try and grab element's title attribute title = getAttr(this.$element, 'title') || getAttr(this.$element, 'data-original-title') || ''; title = title.trim(); } return title; } // New methods }, { key: 'getContent', value: function getContent() { var content = this.$config.content || ''; if (typeof content === 'function') { content = content(this.$element); } if ((typeof content === 'undefined' ? 'undefined' : _typeof(content)) === 'object' && content.nodeType && !content.innerHTML.trim()) { // We have a dom node, but without inner content, so just return an empty string content = ''; } if (typeof content === 'string') { content = content.trim(); } return content; } }], [{ key: 'Default', // Getter overrides get: function get() { return Defaults; } }, { key: 'NAME', get: function get() { return NAME; } }]); return PopOver; }(ToolTip); export default PopOver;