mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-08 06:36:33 +02:00
Dist (#32323)
This commit is contained in:
200
js/dist/modal.js
vendored
200
js/dist/modal.js
vendored
@@ -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('./dom/selector-engine.js')) :
|
||||
typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/event-handler.js', './dom/manipulator.js', './dom/selector-engine.js'], factory) :
|
||||
typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './dom/manipulator', './dom/selector-engine'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Modal = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine));
|
||||
}(this, (function (Data, EventHandler, Manipulator, SelectorEngine) { 'use strict';
|
||||
|
||||
@@ -147,8 +147,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
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; }
|
||||
@@ -158,8 +156,55 @@
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var NAME = 'modal';
|
||||
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 = 'modal';
|
||||
var DATA_KEY = 'bs.modal';
|
||||
var EVENT_KEY = "." + DATA_KEY;
|
||||
var DATA_API_KEY = '.data-api';
|
||||
@@ -167,14 +212,12 @@
|
||||
var Default = {
|
||||
backdrop: true,
|
||||
keyboard: true,
|
||||
focus: true,
|
||||
show: true
|
||||
focus: true
|
||||
};
|
||||
var DefaultType = {
|
||||
backdrop: '(boolean|string)',
|
||||
keyboard: 'boolean',
|
||||
focus: 'boolean',
|
||||
show: 'boolean'
|
||||
focus: 'boolean'
|
||||
};
|
||||
var EVENT_HIDE = "hide" + EVENT_KEY;
|
||||
var EVENT_HIDE_PREVENTED = "hidePrevented" + EVENT_KEY;
|
||||
@@ -206,18 +249,22 @@
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
var Modal = /*#__PURE__*/function () {
|
||||
var Modal = /*#__PURE__*/function (_BaseComponent) {
|
||||
_inheritsLoose(Modal, _BaseComponent);
|
||||
|
||||
function Modal(element, config) {
|
||||
this._config = this._getConfig(config);
|
||||
this._element = element;
|
||||
this._dialog = SelectorEngine__default['default'].findOne(SELECTOR_DIALOG, element);
|
||||
this._backdrop = null;
|
||||
this._isShown = false;
|
||||
this._isBodyOverflowing = false;
|
||||
this._ignoreBackdropClick = false;
|
||||
this._isTransitioning = false;
|
||||
this._scrollbarWidth = 0;
|
||||
Data__default['default'].setData(element, DATA_KEY, this);
|
||||
var _this;
|
||||
|
||||
_this = _BaseComponent.call(this, element) || this;
|
||||
_this._config = _this._getConfig(config);
|
||||
_this._dialog = SelectorEngine__default['default'].findOne(SELECTOR_DIALOG, element);
|
||||
_this._backdrop = null;
|
||||
_this._isShown = false;
|
||||
_this._isBodyOverflowing = false;
|
||||
_this._ignoreBackdropClick = false;
|
||||
_this._isTransitioning = false;
|
||||
_this._scrollbarWidth = 0;
|
||||
return _this;
|
||||
} // Getters
|
||||
|
||||
|
||||
@@ -229,7 +276,7 @@
|
||||
};
|
||||
|
||||
_proto.show = function show(relatedTarget) {
|
||||
var _this = this;
|
||||
var _this2 = this;
|
||||
|
||||
if (this._isShown || this._isTransitioning) {
|
||||
return;
|
||||
@@ -260,23 +307,23 @@
|
||||
this._setResizeEvent();
|
||||
|
||||
EventHandler__default['default'].on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function (event) {
|
||||
return _this.hide(event);
|
||||
return _this2.hide(event);
|
||||
});
|
||||
EventHandler__default['default'].on(this._dialog, EVENT_MOUSEDOWN_DISMISS, function () {
|
||||
EventHandler__default['default'].one(_this._element, EVENT_MOUSEUP_DISMISS, function (event) {
|
||||
if (event.target === _this._element) {
|
||||
_this._ignoreBackdropClick = true;
|
||||
EventHandler__default['default'].one(_this2._element, EVENT_MOUSEUP_DISMISS, function (event) {
|
||||
if (event.target === _this2._element) {
|
||||
_this2._ignoreBackdropClick = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this._showBackdrop(function () {
|
||||
return _this._showElement(relatedTarget);
|
||||
return _this2._showElement(relatedTarget);
|
||||
});
|
||||
};
|
||||
|
||||
_proto.hide = function hide(event) {
|
||||
var _this2 = this;
|
||||
var _this3 = this;
|
||||
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
@@ -314,7 +361,7 @@
|
||||
if (transition) {
|
||||
var transitionDuration = getTransitionDurationFromElement(this._element);
|
||||
EventHandler__default['default'].one(this._element, TRANSITION_END, function (event) {
|
||||
return _this2._hideModal(event);
|
||||
return _this3._hideModal(event);
|
||||
});
|
||||
emulateTransitionEnd(this._element, transitionDuration);
|
||||
} else {
|
||||
@@ -326,16 +373,17 @@
|
||||
[window, this._element, this._dialog].forEach(function (htmlElement) {
|
||||
return EventHandler__default['default'].off(htmlElement, EVENT_KEY);
|
||||
});
|
||||
|
||||
_BaseComponent.prototype.dispose.call(this);
|
||||
/**
|
||||
* `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
|
||||
* Do not move `document` in `htmlElements` array
|
||||
* It will remove `EVENT_CLICK_DATA_API` event that should remain
|
||||
*/
|
||||
|
||||
|
||||
EventHandler__default['default'].off(document, EVENT_FOCUSIN);
|
||||
Data__default['default'].removeData(this._element, DATA_KEY);
|
||||
this._config = null;
|
||||
this._element = null;
|
||||
this._dialog = null;
|
||||
this._backdrop = null;
|
||||
this._isShown = null;
|
||||
@@ -357,7 +405,7 @@
|
||||
};
|
||||
|
||||
_proto._showElement = function _showElement(relatedTarget) {
|
||||
var _this3 = this;
|
||||
var _this4 = this;
|
||||
|
||||
var transition = this._element.classList.contains(CLASS_NAME_FADE);
|
||||
|
||||
@@ -393,12 +441,12 @@
|
||||
}
|
||||
|
||||
var transitionComplete = function transitionComplete() {
|
||||
if (_this3._config.focus) {
|
||||
_this3._element.focus();
|
||||
if (_this4._config.focus) {
|
||||
_this4._element.focus();
|
||||
}
|
||||
|
||||
_this3._isTransitioning = false;
|
||||
EventHandler__default['default'].trigger(_this3._element, EVENT_SHOWN, {
|
||||
_this4._isTransitioning = false;
|
||||
EventHandler__default['default'].trigger(_this4._element, EVENT_SHOWN, {
|
||||
relatedTarget: relatedTarget
|
||||
});
|
||||
};
|
||||
@@ -413,28 +461,28 @@
|
||||
};
|
||||
|
||||
_proto._enforceFocus = function _enforceFocus() {
|
||||
var _this4 = this;
|
||||
var _this5 = this;
|
||||
|
||||
EventHandler__default['default'].off(document, EVENT_FOCUSIN); // guard against infinite focus loop
|
||||
|
||||
EventHandler__default['default'].on(document, EVENT_FOCUSIN, function (event) {
|
||||
if (document !== event.target && _this4._element !== event.target && !_this4._element.contains(event.target)) {
|
||||
_this4._element.focus();
|
||||
if (document !== event.target && _this5._element !== event.target && !_this5._element.contains(event.target)) {
|
||||
_this5._element.focus();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
_proto._setEscapeEvent = function _setEscapeEvent() {
|
||||
var _this5 = this;
|
||||
var _this6 = this;
|
||||
|
||||
if (this._isShown) {
|
||||
EventHandler__default['default'].on(this._element, EVENT_KEYDOWN_DISMISS, function (event) {
|
||||
if (_this5._config.keyboard && event.key === ESCAPE_KEY) {
|
||||
if (_this6._config.keyboard && event.key === ESCAPE_KEY) {
|
||||
event.preventDefault();
|
||||
|
||||
_this5.hide();
|
||||
} else if (!_this5._config.keyboard && event.key === ESCAPE_KEY) {
|
||||
_this5._triggerBackdropTransition();
|
||||
_this6.hide();
|
||||
} else if (!_this6._config.keyboard && event.key === ESCAPE_KEY) {
|
||||
_this6._triggerBackdropTransition();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -443,11 +491,11 @@
|
||||
};
|
||||
|
||||
_proto._setResizeEvent = function _setResizeEvent() {
|
||||
var _this6 = this;
|
||||
var _this7 = this;
|
||||
|
||||
if (this._isShown) {
|
||||
EventHandler__default['default'].on(window, EVENT_RESIZE, function () {
|
||||
return _this6._adjustDialog();
|
||||
return _this7._adjustDialog();
|
||||
});
|
||||
} else {
|
||||
EventHandler__default['default'].off(window, EVENT_RESIZE);
|
||||
@@ -455,7 +503,7 @@
|
||||
};
|
||||
|
||||
_proto._hideModal = function _hideModal() {
|
||||
var _this7 = this;
|
||||
var _this8 = this;
|
||||
|
||||
this._element.style.display = 'none';
|
||||
|
||||
@@ -470,11 +518,11 @@
|
||||
this._showBackdrop(function () {
|
||||
document.body.classList.remove(CLASS_NAME_OPEN);
|
||||
|
||||
_this7._resetAdjustments();
|
||||
_this8._resetAdjustments();
|
||||
|
||||
_this7._resetScrollbar();
|
||||
_this8._resetScrollbar();
|
||||
|
||||
EventHandler__default['default'].trigger(_this7._element, EVENT_HIDDEN);
|
||||
EventHandler__default['default'].trigger(_this8._element, EVENT_HIDDEN);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -485,7 +533,7 @@
|
||||
};
|
||||
|
||||
_proto._showBackdrop = function _showBackdrop(callback) {
|
||||
var _this8 = this;
|
||||
var _this9 = this;
|
||||
|
||||
var animate = this._element.classList.contains(CLASS_NAME_FADE) ? CLASS_NAME_FADE : '';
|
||||
|
||||
@@ -499,8 +547,8 @@
|
||||
|
||||
document.body.appendChild(this._backdrop);
|
||||
EventHandler__default['default'].on(this._element, EVENT_CLICK_DISMISS, function (event) {
|
||||
if (_this8._ignoreBackdropClick) {
|
||||
_this8._ignoreBackdropClick = false;
|
||||
if (_this9._ignoreBackdropClick) {
|
||||
_this9._ignoreBackdropClick = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -508,10 +556,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (_this8._config.backdrop === 'static') {
|
||||
_this8._triggerBackdropTransition();
|
||||
if (_this9._config.backdrop === 'static') {
|
||||
_this9._triggerBackdropTransition();
|
||||
} else {
|
||||
_this8.hide();
|
||||
_this9.hide();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -533,7 +581,7 @@
|
||||
this._backdrop.classList.remove(CLASS_NAME_SHOW);
|
||||
|
||||
var callbackRemove = function callbackRemove() {
|
||||
_this8._removeBackdrop();
|
||||
_this9._removeBackdrop();
|
||||
|
||||
callback();
|
||||
};
|
||||
@@ -552,7 +600,7 @@
|
||||
};
|
||||
|
||||
_proto._triggerBackdropTransition = function _triggerBackdropTransition() {
|
||||
var _this9 = this;
|
||||
var _this10 = this;
|
||||
|
||||
var hideEvent = EventHandler__default['default'].trigger(this._element, EVENT_HIDE_PREVENTED);
|
||||
|
||||
@@ -571,13 +619,13 @@
|
||||
var modalTransitionDuration = getTransitionDurationFromElement(this._dialog);
|
||||
EventHandler__default['default'].off(this._element, TRANSITION_END);
|
||||
EventHandler__default['default'].one(this._element, TRANSITION_END, function () {
|
||||
_this9._element.classList.remove(CLASS_NAME_STATIC);
|
||||
_this10._element.classList.remove(CLASS_NAME_STATIC);
|
||||
|
||||
if (!isModalOverflowing) {
|
||||
EventHandler__default['default'].one(_this9._element, TRANSITION_END, function () {
|
||||
_this9._element.style.overflowY = '';
|
||||
EventHandler__default['default'].one(_this10._element, TRANSITION_END, function () {
|
||||
_this10._element.style.overflowY = '';
|
||||
});
|
||||
emulateTransitionEnd(_this9._element, modalTransitionDuration);
|
||||
emulateTransitionEnd(_this10._element, modalTransitionDuration);
|
||||
}
|
||||
});
|
||||
emulateTransitionEnd(this._element, modalTransitionDuration);
|
||||
@@ -612,7 +660,7 @@
|
||||
};
|
||||
|
||||
_proto._setScrollbar = function _setScrollbar() {
|
||||
var _this10 = this;
|
||||
var _this11 = this;
|
||||
|
||||
if (this._isBodyOverflowing) {
|
||||
// Note: DOMNode.style.paddingRight returns the actual value or '' if not set
|
||||
@@ -622,14 +670,14 @@
|
||||
var actualPadding = element.style.paddingRight;
|
||||
var calculatedPadding = window.getComputedStyle(element)['padding-right'];
|
||||
Manipulator__default['default'].setDataAttribute(element, 'padding-right', actualPadding);
|
||||
element.style.paddingRight = Number.parseFloat(calculatedPadding) + _this10._scrollbarWidth + "px";
|
||||
element.style.paddingRight = Number.parseFloat(calculatedPadding) + _this11._scrollbarWidth + "px";
|
||||
}); // Adjust sticky content margin
|
||||
|
||||
SelectorEngine__default['default'].find(SELECTOR_STICKY_CONTENT).forEach(function (element) {
|
||||
var actualMargin = element.style.marginRight;
|
||||
var calculatedMargin = window.getComputedStyle(element)['margin-right'];
|
||||
Manipulator__default['default'].setDataAttribute(element, 'margin-right', actualMargin);
|
||||
element.style.marginRight = Number.parseFloat(calculatedMargin) - _this10._scrollbarWidth + "px";
|
||||
element.style.marginRight = Number.parseFloat(calculatedMargin) - _this11._scrollbarWidth + "px";
|
||||
}); // Adjust body padding
|
||||
|
||||
var actualPadding = document.body.style.paddingRight;
|
||||
@@ -698,30 +746,24 @@
|
||||
}
|
||||
|
||||
data[config](relatedTarget);
|
||||
} else if (_config.show) {
|
||||
data.show(relatedTarget);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Modal.getInstance = function getInstance(element) {
|
||||
return Data__default['default'].getData(element, DATA_KEY);
|
||||
};
|
||||
|
||||
_createClass(Modal, null, [{
|
||||
key: "VERSION",
|
||||
get: function get() {
|
||||
return VERSION;
|
||||
}
|
||||
}, {
|
||||
_createClass$1(Modal, null, [{
|
||||
key: "Default",
|
||||
get: function get() {
|
||||
return Default;
|
||||
}
|
||||
}, {
|
||||
key: "DATA_KEY",
|
||||
get: function get() {
|
||||
return DATA_KEY;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Modal;
|
||||
}();
|
||||
}(BaseComponent);
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Data Api implementation
|
||||
@@ -730,7 +772,7 @@
|
||||
|
||||
|
||||
EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
||||
var _this11 = this;
|
||||
var _this12 = this;
|
||||
|
||||
var target = getElementFromSelector(this);
|
||||
|
||||
@@ -745,8 +787,8 @@
|
||||
}
|
||||
|
||||
EventHandler__default['default'].one(target, EVENT_HIDDEN, function () {
|
||||
if (isVisible(_this11)) {
|
||||
_this11.focus();
|
||||
if (isVisible(_this12)) {
|
||||
_this12.focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user