1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-09 07:06:36 +02:00
This commit is contained in:
XhmikosR
2020-12-03 16:18:59 +02:00
committed by GitHub
parent cfd00b5eeb
commit cfe31592d7
41 changed files with 2123 additions and 1695 deletions

218
js/dist/tooltip.js vendored
View File

@@ -5,7 +5,7 @@
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('popper.js'), require('./dom/selector-engine.js')) :
typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/event-handler.js', './dom/manipulator.js', 'popper.js', './dom/selector-engine.js'], factory) :
typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './dom/manipulator', 'popper.js', './dom/selector-engine'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tooltip = factory(global.Data, global.EventHandler, global.Manipulator, global.Popper, global.SelectorEngine));
}(this, (function (Data, EventHandler, Manipulator, Popper, SelectorEngine) { 'use strict';
@@ -283,8 +283,6 @@
return createdDocument.body.innerHTML;
}
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
@@ -294,8 +292,55 @@
* ------------------------------------------------------------------------
*/
var NAME = 'tooltip';
var VERSION = '5.0.0-alpha3';
var BaseComponent = /*#__PURE__*/function () {
function BaseComponent(element) {
if (!element) {
return;
}
this._element = element;
Data__default['default'].setData(element, this.constructor.DATA_KEY, this);
}
var _proto = BaseComponent.prototype;
_proto.dispose = function dispose() {
Data__default['default'].removeData(this._element, this.constructor.DATA_KEY);
this._element = null;
}
/** Static */
;
BaseComponent.getInstance = function getInstance(element) {
return Data__default['default'].getData(element, this.DATA_KEY);
};
_createClass(BaseComponent, null, [{
key: "VERSION",
get: function get() {
return VERSION;
}
}]);
return BaseComponent;
}();
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _defineProperties$1(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); } }
function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'tooltip';
var DATA_KEY = 'bs.tooltip';
var EVENT_KEY = "." + DATA_KEY;
var CLASS_PREFIX = 'bs-tooltip';
@@ -314,6 +359,7 @@
container: '(string|element|boolean)',
fallbackPlacement: '(string|array)',
boundary: '(string|element)',
customClass: '(string|function)',
sanitize: 'boolean',
sanitizeFn: '(null|function)',
allowList: 'object',
@@ -328,7 +374,7 @@
};
var Default = {
animation: true,
template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-arrow"></div>' + '<div class="tooltip-inner"></div></div>',
template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-arrow"></div>' + '<div class="tooltip-inner"></div>' + '</div>',
trigger: 'hover focus',
title: '',
delay: 0,
@@ -339,6 +385,7 @@
container: false,
fallbackPlacement: 'flip',
boundary: 'scrollParent',
customClass: '',
sanitize: true,
sanitizeFn: null,
allowList: DefaultAllowlist,
@@ -372,26 +419,30 @@
* ------------------------------------------------------------------------
*/
var Tooltip = /*#__PURE__*/function () {
var Tooltip = /*#__PURE__*/function (_BaseComponent) {
_inheritsLoose(Tooltip, _BaseComponent);
function Tooltip(element, config) {
var _this;
if (typeof Popper__default['default'] === 'undefined') {
throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)');
} // private
}
_this = _BaseComponent.call(this, element) || this; // private
this._isEnabled = true;
this._timeout = 0;
this._hoverState = '';
this._activeTrigger = {};
this._popper = null; // Protected
_this._isEnabled = true;
_this._timeout = 0;
_this._hoverState = '';
_this._activeTrigger = {};
_this._popper = null; // Protected
this.element = element;
this.config = this._getConfig(config);
this.tip = null;
_this.config = _this._getConfig(config);
_this.tip = null;
this._setListeners();
_this._setListeners();
Data__default['default'].setData(element, this.constructor.DATA_KEY, this);
return _this;
} // Getters
@@ -444,9 +495,8 @@
_proto.dispose = function dispose() {
clearTimeout(this._timeout);
Data__default['default'].removeData(this.element, this.constructor.DATA_KEY);
EventHandler__default['default'].off(this.element, this.constructor.EVENT_KEY);
EventHandler__default['default'].off(this.element.closest("." + CLASS_NAME_MODAL), 'hide.bs.modal', this._hideModalHandler);
EventHandler__default['default'].off(this._element, this.constructor.EVENT_KEY);
EventHandler__default['default'].off(this._element.closest("." + CLASS_NAME_MODAL), 'hide.bs.modal', this._hideModalHandler);
if (this.tip) {
this.tip.parentNode.removeChild(this.tip);
@@ -462,22 +512,23 @@
}
this._popper = null;
this.element = null;
this.config = null;
this.tip = null;
_BaseComponent.prototype.dispose.call(this);
};
_proto.show = function show() {
var _this = this;
var _this2 = this;
if (this.element.style.display === 'none') {
if (this._element.style.display === 'none') {
throw new Error('Please use show on visible elements');
}
if (this.isWithContent() && this._isEnabled) {
var showEvent = EventHandler__default['default'].trigger(this.element, this.constructor.Event.SHOW);
var shadowRoot = findShadowRoot(this.element);
var isInTheDom = shadowRoot === null ? this.element.ownerDocument.documentElement.contains(this.element) : shadowRoot.contains(this.element);
var showEvent = EventHandler__default['default'].trigger(this._element, this.constructor.Event.SHOW);
var shadowRoot = findShadowRoot(this._element);
var isInTheDom = shadowRoot === null ? this._element.ownerDocument.documentElement.contains(this._element) : shadowRoot.contains(this._element);
if (showEvent.defaultPrevented || !isInTheDom) {
return;
@@ -486,14 +537,16 @@
var tip = this.getTipElement();
var tipId = getUID(this.constructor.NAME);
tip.setAttribute('id', tipId);
this.element.setAttribute('aria-describedby', tipId);
this._element.setAttribute('aria-describedby', tipId);
this.setContent();
if (this.config.animation) {
tip.classList.add(CLASS_NAME_FADE);
}
var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;
var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this._element) : this.config.placement;
var attachment = this._getAttachment(placement);
@@ -503,17 +556,25 @@
Data__default['default'].setData(tip, this.constructor.DATA_KEY, this);
if (!this.element.ownerDocument.documentElement.contains(this.tip)) {
if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
container.appendChild(tip);
}
EventHandler__default['default'].trigger(this.element, this.constructor.Event.INSERTED);
this._popper = new Popper__default['default'](this.element, tip, this._getPopperConfig(attachment));
tip.classList.add(CLASS_NAME_SHOW); // If this is a touch-enabled device we add extra
EventHandler__default['default'].trigger(this._element, this.constructor.Event.INSERTED);
this._popper = new Popper__default['default'](this._element, tip, this._getPopperConfig(attachment));
tip.classList.add(CLASS_NAME_SHOW);
var customClass = typeof this.config.customClass === 'function' ? this.config.customClass() : this.config.customClass;
if (customClass) {
var _tip$classList;
(_tip$classList = tip.classList).add.apply(_tip$classList, customClass.split(' '));
} // If this is a touch-enabled device we add extra
// empty mouseover listeners to the body's immediate children;
// only needed because of broken event delegation on iOS
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
if ('ontouchstart' in document.documentElement) {
var _ref;
@@ -523,16 +584,16 @@
}
var complete = function complete() {
if (_this.config.animation) {
_this._fixTransition();
if (_this2.config.animation) {
_this2._fixTransition();
}
var prevHoverState = _this._hoverState;
_this._hoverState = null;
EventHandler__default['default'].trigger(_this.element, _this.constructor.Event.SHOWN);
var prevHoverState = _this2._hoverState;
_this2._hoverState = null;
EventHandler__default['default'].trigger(_this2._element, _this2.constructor.Event.SHOWN);
if (prevHoverState === HOVER_STATE_OUT) {
_this._leave(null, _this);
_this2._leave(null, _this2);
}
};
@@ -547,7 +608,7 @@
};
_proto.hide = function hide() {
var _this2 = this;
var _this3 = this;
if (!this._popper) {
return;
@@ -556,20 +617,20 @@
var tip = this.getTipElement();
var complete = function complete() {
if (_this2._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
if (_this3._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
tip.parentNode.removeChild(tip);
}
_this2._cleanTipClass();
_this3._cleanTipClass();
_this2.element.removeAttribute('aria-describedby');
_this3._element.removeAttribute('aria-describedby');
EventHandler__default['default'].trigger(_this2.element, _this2.constructor.Event.HIDDEN);
EventHandler__default['default'].trigger(_this3._element, _this3.constructor.Event.HIDDEN);
_this2._popper.destroy();
_this3._popper.destroy();
};
var hideEvent = EventHandler__default['default'].trigger(this.element, this.constructor.Event.HIDE);
var hideEvent = EventHandler__default['default'].trigger(this._element, this.constructor.Event.HIDE);
if (hideEvent.defaultPrevented) {
return;
@@ -664,10 +725,10 @@
};
_proto.getTitle = function getTitle() {
var title = this.element.getAttribute('data-bs-original-title');
var title = this._element.getAttribute('data-bs-original-title');
if (!title) {
title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
title = typeof this.config.title === 'function' ? this.config.title.call(this._element) : this.config.title;
}
return title;
@@ -675,7 +736,7 @@
;
_proto._getPopperConfig = function _getPopperConfig(attachment) {
var _this3 = this;
var _this4 = this;
var defaultBsConfig = {
placement: attachment,
@@ -693,11 +754,11 @@
},
onCreate: function onCreate(data) {
if (data.originalPlacement !== data.placement) {
_this3._handlePopperPlacementChange(data);
_this4._handlePopperPlacementChange(data);
}
},
onUpdate: function onUpdate(data) {
return _this3._handlePopperPlacementChange(data);
return _this4._handlePopperPlacementChange(data);
}
};
return _extends({}, defaultBsConfig, this.config.popperConfig);
@@ -708,13 +769,13 @@
};
_proto._getOffset = function _getOffset() {
var _this4 = this;
var _this5 = this;
var offset = {};
if (typeof this.config.offset === 'function') {
offset.fn = function (data) {
data.offsets = _extends({}, data.offsets, _this4.config.offset(data.offsets, _this4.element) || {});
data.offsets = _extends({}, data.offsets, _this5.config.offset(data.offsets, _this5._element) || {});
return data;
};
} else {
@@ -741,33 +802,33 @@
};
_proto._setListeners = function _setListeners() {
var _this5 = this;
var _this6 = this;
var triggers = this.config.trigger.split(' ');
triggers.forEach(function (trigger) {
if (trigger === 'click') {
EventHandler__default['default'].on(_this5.element, _this5.constructor.Event.CLICK, _this5.config.selector, function (event) {
return _this5.toggle(event);
EventHandler__default['default'].on(_this6._element, _this6.constructor.Event.CLICK, _this6.config.selector, function (event) {
return _this6.toggle(event);
});
} else if (trigger !== TRIGGER_MANUAL) {
var eventIn = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSEENTER : _this5.constructor.Event.FOCUSIN;
var eventOut = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSELEAVE : _this5.constructor.Event.FOCUSOUT;
EventHandler__default['default'].on(_this5.element, eventIn, _this5.config.selector, function (event) {
return _this5._enter(event);
var eventIn = trigger === TRIGGER_HOVER ? _this6.constructor.Event.MOUSEENTER : _this6.constructor.Event.FOCUSIN;
var eventOut = trigger === TRIGGER_HOVER ? _this6.constructor.Event.MOUSELEAVE : _this6.constructor.Event.FOCUSOUT;
EventHandler__default['default'].on(_this6._element, eventIn, _this6.config.selector, function (event) {
return _this6._enter(event);
});
EventHandler__default['default'].on(_this5.element, eventOut, _this5.config.selector, function (event) {
return _this5._leave(event);
EventHandler__default['default'].on(_this6._element, eventOut, _this6.config.selector, function (event) {
return _this6._leave(event);
});
}
});
this._hideModalHandler = function () {
if (_this5.element) {
_this5.hide();
if (_this6._element) {
_this6.hide();
}
};
EventHandler__default['default'].on(this.element.closest("." + CLASS_NAME_MODAL), 'hide.bs.modal', this._hideModalHandler);
EventHandler__default['default'].on(this._element.closest("." + CLASS_NAME_MODAL), 'hide.bs.modal', this._hideModalHandler);
if (this.config.selector) {
this.config = _extends({}, this.config, {
@@ -780,12 +841,18 @@
};
_proto._fixTitle = function _fixTitle() {
var title = this.element.getAttribute('title');
var originalTitleType = typeof this.element.getAttribute('data-bs-original-title');
var title = this._element.getAttribute('title');
var originalTitleType = typeof this._element.getAttribute('data-bs-original-title');
if (title || originalTitleType !== 'string') {
this.element.setAttribute('data-bs-original-title', title || '');
this.element.setAttribute('title', '');
this._element.setAttribute('data-bs-original-title', title || '');
if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
this._element.setAttribute('aria-label', title);
}
this._element.setAttribute('title', '');
}
};
@@ -865,7 +932,7 @@
};
_proto._getConfig = function _getConfig(config) {
var dataAttributes = Manipulator__default['default'].getDataAttributes(this.element);
var dataAttributes = Manipulator__default['default'].getDataAttributes(this._element);
Object.keys(dataAttributes).forEach(function (dataAttr) {
if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
delete dataAttributes[dataAttr];
@@ -977,16 +1044,7 @@
});
};
Tooltip.getInstance = function getInstance(element) {
return Data__default['default'].getData(element, DATA_KEY);
};
_createClass(Tooltip, null, [{
key: "VERSION",
get: function get() {
return VERSION;
}
}, {
_createClass$1(Tooltip, null, [{
key: "Default",
get: function get() {
return Default;
@@ -1019,7 +1077,7 @@
}]);
return Tooltip;
}();
}(BaseComponent);
/**
* ------------------------------------------------------------------------
* jQuery