diff options
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/modal.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/dist/modal.js | 336 |
1 files changed, 162 insertions, 174 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/modal.js b/vendor/twbs/bootstrap/js/dist/modal.js index 43b7e61be..c808df191 100644 --- a/vendor/twbs/bootstrap/js/dist/modal.js +++ b/vendor/twbs/bootstrap/js/dist/modal.js @@ -1,67 +1,22 @@ /*! - * Bootstrap modal.js v4.3.1 (https://getbootstrap.com/) - * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) - * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * Bootstrap modal.js v4.5.2 (https://getbootstrap.com/) + * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) : typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) : - (global = global || self, global.Modal = factory(global.jQuery, global.Util)); -}(this, function ($, Util) { 'use strict'; - - $ = $ && $.hasOwnProperty('default') ? $['default'] : $; - Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util; - - 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; - } - - 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; - } + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Modal = factory(global.jQuery, global.Util)); +}(this, (function ($, Util) { 'use strict'; - return obj; - } + $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $; + Util = Util && Object.prototype.hasOwnProperty.call(Util, 'default') ? Util['default'] : Util; - function _objectSpread(target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i] != null ? arguments[i] : {}; - var ownKeys = Object.keys(source); + 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); } - 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 _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; } /** * ------------------------------------------------------------------------ * Constants @@ -69,7 +24,7 @@ */ var NAME = 'modal'; - var VERSION = '4.3.1'; + var VERSION = '4.5.2'; var DATA_KEY = 'bs.modal'; var EVENT_KEY = "." + DATA_KEY; var DATA_API_KEY = '.data-api'; @@ -88,49 +43,42 @@ focus: 'boolean', show: 'boolean' }; - var Event = { - HIDE: "hide" + EVENT_KEY, - HIDDEN: "hidden" + EVENT_KEY, - SHOW: "show" + EVENT_KEY, - SHOWN: "shown" + EVENT_KEY, - FOCUSIN: "focusin" + EVENT_KEY, - RESIZE: "resize" + EVENT_KEY, - CLICK_DISMISS: "click.dismiss" + EVENT_KEY, - KEYDOWN_DISMISS: "keydown.dismiss" + EVENT_KEY, - MOUSEUP_DISMISS: "mouseup.dismiss" + EVENT_KEY, - MOUSEDOWN_DISMISS: "mousedown.dismiss" + EVENT_KEY, - CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY - }; - var ClassName = { - SCROLLABLE: 'modal-dialog-scrollable', - SCROLLBAR_MEASURER: 'modal-scrollbar-measure', - BACKDROP: 'modal-backdrop', - OPEN: 'modal-open', - FADE: 'fade', - SHOW: 'show' - }; - var Selector = { - DIALOG: '.modal-dialog', - MODAL_BODY: '.modal-body', - DATA_TOGGLE: '[data-toggle="modal"]', - DATA_DISMISS: '[data-dismiss="modal"]', - FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top', - STICKY_CONTENT: '.sticky-top' - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ - - }; + var EVENT_HIDE = "hide" + EVENT_KEY; + var EVENT_HIDE_PREVENTED = "hidePrevented" + EVENT_KEY; + var EVENT_HIDDEN = "hidden" + EVENT_KEY; + var EVENT_SHOW = "show" + EVENT_KEY; + var EVENT_SHOWN = "shown" + EVENT_KEY; + var EVENT_FOCUSIN = "focusin" + EVENT_KEY; + var EVENT_RESIZE = "resize" + EVENT_KEY; + var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY; + var EVENT_KEYDOWN_DISMISS = "keydown.dismiss" + EVENT_KEY; + var EVENT_MOUSEUP_DISMISS = "mouseup.dismiss" + EVENT_KEY; + var EVENT_MOUSEDOWN_DISMISS = "mousedown.dismiss" + EVENT_KEY; + var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY; + var CLASS_NAME_SCROLLABLE = 'modal-dialog-scrollable'; + var CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure'; + var CLASS_NAME_BACKDROP = 'modal-backdrop'; + var CLASS_NAME_OPEN = 'modal-open'; + var CLASS_NAME_FADE = 'fade'; + var CLASS_NAME_SHOW = 'show'; + var CLASS_NAME_STATIC = 'modal-static'; + var SELECTOR_DIALOG = '.modal-dialog'; + var SELECTOR_MODAL_BODY = '.modal-body'; + var SELECTOR_DATA_TOGGLE = '[data-toggle="modal"]'; + var SELECTOR_DATA_DISMISS = '[data-dismiss="modal"]'; + var SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'; + var SELECTOR_STICKY_CONTENT = '.sticky-top'; + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - var Modal = - /*#__PURE__*/ - function () { + var Modal = /*#__PURE__*/function () { function Modal(element, config) { this._config = this._getConfig(config); this._element = element; - this._dialog = element.querySelector(Selector.DIALOG); + this._dialog = element.querySelector(SELECTOR_DIALOG); this._backdrop = null; this._isShown = false; this._isBodyOverflowing = false; @@ -154,11 +102,11 @@ return; } - if ($(this._element).hasClass(ClassName.FADE)) { + if ($(this._element).hasClass(CLASS_NAME_FADE)) { this._isTransitioning = true; } - var showEvent = $.Event(Event.SHOW, { + var showEvent = $.Event(EVENT_SHOW, { relatedTarget: relatedTarget }); $(this._element).trigger(showEvent); @@ -179,11 +127,11 @@ this._setResizeEvent(); - $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) { + $(this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function (event) { return _this.hide(event); }); - $(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () { - $(_this._element).one(Event.MOUSEUP_DISMISS, function (event) { + $(this._dialog).on(EVENT_MOUSEDOWN_DISMISS, function () { + $(_this._element).one(EVENT_MOUSEUP_DISMISS, function (event) { if ($(event.target).is(_this._element)) { _this._ignoreBackdropClick = true; } @@ -206,7 +154,7 @@ return; } - var hideEvent = $.Event(Event.HIDE); + var hideEvent = $.Event(EVENT_HIDE); $(this._element).trigger(hideEvent); if (!this._isShown || hideEvent.isDefaultPrevented()) { @@ -214,7 +162,7 @@ } this._isShown = false; - var transition = $(this._element).hasClass(ClassName.FADE); + var transition = $(this._element).hasClass(CLASS_NAME_FADE); if (transition) { this._isTransitioning = true; @@ -224,10 +172,10 @@ this._setResizeEvent(); - $(document).off(Event.FOCUSIN); - $(this._element).removeClass(ClassName.SHOW); - $(this._element).off(Event.CLICK_DISMISS); - $(this._dialog).off(Event.MOUSEDOWN_DISMISS); + $(document).off(EVENT_FOCUSIN); + $(this._element).removeClass(CLASS_NAME_SHOW); + $(this._element).off(EVENT_CLICK_DISMISS); + $(this._dialog).off(EVENT_MOUSEDOWN_DISMISS); if (transition) { var transitionDuration = Util.getTransitionDurationFromElement(this._element); @@ -244,12 +192,12 @@ return $(htmlElement).off(EVENT_KEY); }); /** - * `document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API` + * `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 + * It will remove `EVENT_CLICK_DATA_API` event that should remain */ - $(document).off(Event.FOCUSIN); + $(document).off(EVENT_FOCUSIN); $.removeData(this._element, DATA_KEY); this._config = null; this._element = null; @@ -268,15 +216,53 @@ ; _proto._getConfig = function _getConfig(config) { - config = _objectSpread({}, Default, config); + config = _extends({}, Default, config); Util.typeCheckConfig(NAME, config, DefaultType); return config; }; - _proto._showElement = function _showElement(relatedTarget) { + _proto._triggerBackdropTransition = function _triggerBackdropTransition() { var _this3 = this; - var transition = $(this._element).hasClass(ClassName.FADE); + if (this._config.backdrop === 'static') { + var hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED); + $(this._element).trigger(hideEventPrevented); + + if (hideEventPrevented.defaultPrevented) { + return; + } + + var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight; + + if (!isModalOverflowing) { + this._element.style.overflowY = 'hidden'; + } + + this._element.classList.add(CLASS_NAME_STATIC); + + var modalTransitionDuration = Util.getTransitionDurationFromElement(this._dialog); + $(this._element).off(Util.TRANSITION_END); + $(this._element).one(Util.TRANSITION_END, function () { + _this3._element.classList.remove(CLASS_NAME_STATIC); + + if (!isModalOverflowing) { + $(_this3._element).one(Util.TRANSITION_END, function () { + _this3._element.style.overflowY = ''; + }).emulateTransitionEnd(_this3._element, modalTransitionDuration); + } + }).emulateTransitionEnd(modalTransitionDuration); + + this._element.focus(); + } else { + this.hide(); + } + }; + + _proto._showElement = function _showElement(relatedTarget) { + var _this4 = this; + + var transition = $(this._element).hasClass(CLASS_NAME_FADE); + var modalBody = this._dialog ? this._dialog.querySelector(SELECTOR_MODAL_BODY) : null; if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) { // Don't move modal's DOM position @@ -289,8 +275,10 @@ this._element.setAttribute('aria-modal', true); - if ($(this._dialog).hasClass(ClassName.SCROLLABLE)) { - this._dialog.querySelector(Selector.MODAL_BODY).scrollTop = 0; + this._element.setAttribute('role', 'dialog'); + + if ($(this._dialog).hasClass(CLASS_NAME_SCROLLABLE) && modalBody) { + modalBody.scrollTop = 0; } else { this._element.scrollTop = 0; } @@ -299,23 +287,23 @@ Util.reflow(this._element); } - $(this._element).addClass(ClassName.SHOW); + $(this._element).addClass(CLASS_NAME_SHOW); if (this._config.focus) { this._enforceFocus(); } - var shownEvent = $.Event(Event.SHOWN, { + var shownEvent = $.Event(EVENT_SHOWN, { relatedTarget: relatedTarget }); var transitionComplete = function transitionComplete() { - if (_this3._config.focus) { - _this3._element.focus(); + if (_this4._config.focus) { + _this4._element.focus(); } - _this3._isTransitioning = false; - $(_this3._element).trigger(shownEvent); + _this4._isTransitioning = false; + $(_this4._element).trigger(shownEvent); }; if (transition) { @@ -327,46 +315,48 @@ }; _proto._enforceFocus = function _enforceFocus() { - var _this4 = this; + var _this5 = this; - $(document).off(Event.FOCUSIN) // Guard against infinite focus loop - .on(Event.FOCUSIN, function (event) { - if (document !== event.target && _this4._element !== event.target && $(_this4._element).has(event.target).length === 0) { - _this4._element.focus(); + $(document).off(EVENT_FOCUSIN) // Guard against infinite focus loop + .on(EVENT_FOCUSIN, function (event) { + if (document !== event.target && _this5._element !== event.target && $(_this5._element).has(event.target).length === 0) { + _this5._element.focus(); } }); }; _proto._setEscapeEvent = function _setEscapeEvent() { - var _this5 = this; + var _this6 = this; - if (this._isShown && this._config.keyboard) { - $(this._element).on(Event.KEYDOWN_DISMISS, function (event) { - if (event.which === ESCAPE_KEYCODE) { + if (this._isShown) { + $(this._element).on(EVENT_KEYDOWN_DISMISS, function (event) { + if (_this6._config.keyboard && event.which === ESCAPE_KEYCODE) { event.preventDefault(); - _this5.hide(); + _this6.hide(); + } else if (!_this6._config.keyboard && event.which === ESCAPE_KEYCODE) { + _this6._triggerBackdropTransition(); } }); } else if (!this._isShown) { - $(this._element).off(Event.KEYDOWN_DISMISS); + $(this._element).off(EVENT_KEYDOWN_DISMISS); } }; _proto._setResizeEvent = function _setResizeEvent() { - var _this6 = this; + var _this7 = this; if (this._isShown) { - $(window).on(Event.RESIZE, function (event) { - return _this6.handleUpdate(event); + $(window).on(EVENT_RESIZE, function (event) { + return _this7.handleUpdate(event); }); } else { - $(window).off(Event.RESIZE); + $(window).off(EVENT_RESIZE); } }; _proto._hideModal = function _hideModal() { - var _this7 = this; + var _this8 = this; this._element.style.display = 'none'; @@ -374,16 +364,18 @@ this._element.removeAttribute('aria-modal'); + this._element.removeAttribute('role'); + this._isTransitioning = false; this._showBackdrop(function () { - $(document.body).removeClass(ClassName.OPEN); + $(document.body).removeClass(CLASS_NAME_OPEN); - _this7._resetAdjustments(); + _this8._resetAdjustments(); - _this7._resetScrollbar(); + _this8._resetScrollbar(); - $(_this7._element).trigger(Event.HIDDEN); + $(_this8._element).trigger(EVENT_HIDDEN); }); }; @@ -395,22 +387,22 @@ }; _proto._showBackdrop = function _showBackdrop(callback) { - var _this8 = this; + var _this9 = this; - var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : ''; + var animate = $(this._element).hasClass(CLASS_NAME_FADE) ? CLASS_NAME_FADE : ''; if (this._isShown && this._config.backdrop) { this._backdrop = document.createElement('div'); - this._backdrop.className = ClassName.BACKDROP; + this._backdrop.className = CLASS_NAME_BACKDROP; if (animate) { this._backdrop.classList.add(animate); } $(this._backdrop).appendTo(document.body); - $(this._element).on(Event.CLICK_DISMISS, function (event) { - if (_this8._ignoreBackdropClick) { - _this8._ignoreBackdropClick = false; + $(this._element).on(EVENT_CLICK_DISMISS, function (event) { + if (_this9._ignoreBackdropClick) { + _this9._ignoreBackdropClick = false; return; } @@ -418,18 +410,14 @@ return; } - if (_this8._config.backdrop === 'static') { - _this8._element.focus(); - } else { - _this8.hide(); - } + _this9._triggerBackdropTransition(); }); if (animate) { Util.reflow(this._backdrop); } - $(this._backdrop).addClass(ClassName.SHOW); + $(this._backdrop).addClass(CLASS_NAME_SHOW); if (!callback) { return; @@ -443,17 +431,17 @@ var backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop); $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(backdropTransitionDuration); } else if (!this._isShown && this._backdrop) { - $(this._backdrop).removeClass(ClassName.SHOW); + $(this._backdrop).removeClass(CLASS_NAME_SHOW); var callbackRemove = function callbackRemove() { - _this8._removeBackdrop(); + _this9._removeBackdrop(); if (callback) { callback(); } }; - if ($(this._element).hasClass(ClassName.FADE)) { + if ($(this._element).hasClass(CLASS_NAME_FADE)) { var _backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop); $(this._backdrop).one(Util.TRANSITION_END, callbackRemove).emulateTransitionEnd(_backdropTransitionDuration); @@ -488,29 +476,29 @@ _proto._checkScrollbar = function _checkScrollbar() { var rect = document.body.getBoundingClientRect(); - this._isBodyOverflowing = rect.left + rect.right < window.innerWidth; + this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth; this._scrollbarWidth = this._getScrollbarWidth(); }; _proto._setScrollbar = function _setScrollbar() { - var _this9 = this; + var _this10 = this; if (this._isBodyOverflowing) { // Note: DOMNode.style.paddingRight returns the actual value or '' if not set // while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set - var fixedContent = [].slice.call(document.querySelectorAll(Selector.FIXED_CONTENT)); - var stickyContent = [].slice.call(document.querySelectorAll(Selector.STICKY_CONTENT)); // Adjust fixed content padding + var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT)); + var stickyContent = [].slice.call(document.querySelectorAll(SELECTOR_STICKY_CONTENT)); // Adjust fixed content padding $(fixedContent).each(function (index, element) { var actualPadding = element.style.paddingRight; var calculatedPadding = $(element).css('padding-right'); - $(element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this9._scrollbarWidth + "px"); + $(element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this10._scrollbarWidth + "px"); }); // Adjust sticky content margin $(stickyContent).each(function (index, element) { var actualMargin = element.style.marginRight; var calculatedMargin = $(element).css('margin-right'); - $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this9._scrollbarWidth + "px"); + $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this10._scrollbarWidth + "px"); }); // Adjust body padding var actualPadding = document.body.style.paddingRight; @@ -518,19 +506,19 @@ $(document.body).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + "px"); } - $(document.body).addClass(ClassName.OPEN); + $(document.body).addClass(CLASS_NAME_OPEN); }; _proto._resetScrollbar = function _resetScrollbar() { // Restore fixed content padding - var fixedContent = [].slice.call(document.querySelectorAll(Selector.FIXED_CONTENT)); + var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT)); $(fixedContent).each(function (index, element) { var padding = $(element).data('padding-right'); $(element).removeData('padding-right'); element.style.paddingRight = padding ? padding : ''; }); // Restore sticky content - var elements = [].slice.call(document.querySelectorAll("" + Selector.STICKY_CONTENT)); + var elements = [].slice.call(document.querySelectorAll("" + SELECTOR_STICKY_CONTENT)); $(elements).each(function (index, element) { var margin = $(element).data('margin-right'); @@ -547,7 +535,7 @@ _proto._getScrollbarWidth = function _getScrollbarWidth() { // thx d.walsh var scrollDiv = document.createElement('div'); - scrollDiv.className = ClassName.SCROLLBAR_MEASURER; + scrollDiv.className = CLASS_NAME_SCROLLBAR_MEASURER; document.body.appendChild(scrollDiv); var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth; document.body.removeChild(scrollDiv); @@ -559,7 +547,7 @@ return this.each(function () { var data = $(this).data(DATA_KEY); - var _config = _objectSpread({}, Default, $(this).data(), typeof config === 'object' && config ? config : {}); + var _config = _extends({}, Default, $(this).data(), typeof config === 'object' && config ? config : {}); if (!data) { data = new Modal(this, _config); @@ -599,8 +587,8 @@ */ - $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { - var _this10 = this; + $(document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { + var _this11 = this; var target; var selector = Util.getSelectorFromElement(this); @@ -609,21 +597,21 @@ target = document.querySelector(selector); } - var config = $(target).data(DATA_KEY) ? 'toggle' : _objectSpread({}, $(target).data(), $(this).data()); + var config = $(target).data(DATA_KEY) ? 'toggle' : _extends({}, $(target).data(), $(this).data()); if (this.tagName === 'A' || this.tagName === 'AREA') { event.preventDefault(); } - var $target = $(target).one(Event.SHOW, function (showEvent) { + var $target = $(target).one(EVENT_SHOW, function (showEvent) { if (showEvent.isDefaultPrevented()) { // Only register focus restorer if modal will actually get shown return; } - $target.one(Event.HIDDEN, function () { - if ($(_this10).is(':visible')) { - _this10.focus(); + $target.one(EVENT_HIDDEN, function () { + if ($(_this11).is(':visible')) { + _this11.focus(); } }); }); @@ -646,5 +634,5 @@ return Modal; -})); +}))); //# sourceMappingURL=modal.js.map |