UNPKG

bootstrap-vue

Version:

BootstrapVue, with over 40 plugins and more than 75 custom components, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated WAI-ARIA accessibility markup.

198 lines (156 loc) 6.16 kB
"use strict"; exports.__esModule = true; exports.default = exports.VBTooltip = void 0; var _popper = _interopRequireDefault(require("popper.js")); var _tooltip = _interopRequireDefault(require("../../utils/tooltip.class")); var _warn = _interopRequireDefault(require("../../utils/warn")); var _config = require("../../utils/config"); var _env = require("../../utils/env"); var _inspect = require("../../utils/inspect"); var _object = require("../../utils/object"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } // Key which we use to store tooltip object on element var BV_TOOLTIP = '__BV_ToolTip__'; // Valid event triggers var validTriggers = { focus: true, hover: true, click: true, blur: true // Build a ToolTip config based on bindings (if any) // Arguments and modifiers take precedence over passed value config object /* istanbul ignore next: not easy to test */ }; var parseBindings = function parseBindings(bindings) /* istanbul ignore next: not easy to test */ { // We start out with a basic config var NAME = 'BTooltip'; var config = { delay: (0, _config.getComponentConfig)(NAME, 'delay'), boundary: String((0, _config.getComponentConfig)(NAME, 'boundary')), boundaryPadding: parseInt((0, _config.getComponentConfig)(NAME, 'boundaryPadding'), 10) || 0 // Process bindings.value }; if ((0, _inspect.isString)(bindings.value)) { // Value is tooltip content (html optionally supported) config.title = bindings.value; } else if ((0, _inspect.isFunction)(bindings.value)) { // Title generator function config.title = bindings.value; } else if ((0, _inspect.isObject)(bindings.value)) { // Value is config object, so merge config = _objectSpread({}, config, bindings.value); } // If argument, assume element ID of container element if (bindings.arg) { // Element ID specified as arg // We must prepend '#' to become a CSS selector config.container = "#".concat(bindings.arg); } // Process modifiers (0, _object.keys)(bindings.modifiers).forEach(function (mod) { if (/^html$/.test(mod)) { // Title allows HTML config.html = true; } else if (/^nofade$/.test(mod)) { // No animation config.animation = false; } else if (/^(auto|top(left|right)?|bottom(left|right)?|left(top|bottom)?|right(top|bottom)?)$/.test(mod)) { // Placement of tooltip config.placement = mod; } else if (/^(window|viewport|scrollParent)$/.test(mod)) { // Boundary of tooltip config.boundary = mod; } else if (/^d\d+$/.test(mod)) { // Delay value var delay = parseInt(mod.slice(1), 10) || 0; if (delay) { config.delay = delay; } } else if (/^o-?\d+$/.test(mod)) { // Offset value, negative allowed var offset = parseInt(mod.slice(1), 10) || 0; if (offset) { config.offset = offset; } } }); // Special handling of event trigger modifiers trigger is // a space separated list var selectedTriggers = {}; // Parse current config object trigger var triggers = (0, _inspect.isString)(config.trigger) ? config.trigger.trim().split(/\s+/) : []; triggers.forEach(function (trigger) { if (validTriggers[trigger]) { selectedTriggers[trigger] = true; } }); // Parse modifiers for triggers (0, _object.keys)(validTriggers).forEach(function (trigger) { if (bindings.modifiers[trigger]) { selectedTriggers[trigger] = true; } }); // Sanitize triggers config.trigger = (0, _object.keys)(selectedTriggers).join(' '); if (config.trigger === 'blur') { // Blur by itself is useless, so convert it to 'focus' config.trigger = 'focus'; } if (!config.trigger) { // Remove trigger config delete config.trigger; } return config; }; // Add or update ToolTip on our element var applyTooltip = function applyTooltip(el, bindings, vnode) { if (!_env.isBrowser) { /* istanbul ignore next */ return; } if (!_popper.default) { // Popper is required for ToolTips to work /* istanbul ignore next */ (0, _warn.default)('v-b-tooltip: Popper.js is required for ToolTips to work'); /* istanbul ignore next */ return; } var config = parseBindings(bindings); if (el[BV_TOOLTIP]) { el[BV_TOOLTIP].updateConfig(config); } else { el[BV_TOOLTIP] = new _tooltip.default(el, config, vnode.context.$root); } }; // Remove ToolTip on our element var removeTooltip = function removeTooltip(el) { if (el[BV_TOOLTIP]) { el[BV_TOOLTIP].destroy(); el[BV_TOOLTIP] = null; delete el[BV_TOOLTIP]; } }; /* * Export our directive */ var VBTooltip = { bind: function bind(el, bindings, vnode) { applyTooltip(el, bindings, vnode); }, inserted: function inserted(el, bindings, vnode) { applyTooltip(el, bindings, vnode); }, update: function update(el, bindings, vnode) /* istanbul ignore next: not easy to test */ { if (bindings.value !== bindings.oldValue) { applyTooltip(el, bindings, vnode); } }, componentUpdated: function componentUpdated(el, bindings, vnode) /* istanbul ignore next: not easy to test */ { if (bindings.value !== bindings.oldValue) { applyTooltip(el, bindings, vnode); } }, unbind: function unbind(el) { removeTooltip(el); } }; exports.VBTooltip = VBTooltip; var _default = VBTooltip; exports.default = _default;