diff options
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/modal.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/dist/modal.js | 178 |
1 files changed, 87 insertions, 91 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/modal.js b/vendor/twbs/bootstrap/js/dist/modal.js index dbdb64951..5be3c2069 100644 --- a/vendor/twbs/bootstrap/js/dist/modal.js +++ b/vendor/twbs/bootstrap/js/dist/modal.js @@ -1,6 +1,6 @@ /*! - * Bootstrap modal.js v4.4.1 (https://getbootstrap.com/) - * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) + * Bootstrap modal.js v4.5.0 (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/master/LICENSE) */ (function (global, factory) { @@ -9,8 +9,8 @@ (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; + $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $; + Util = Util && Object.prototype.hasOwnProperty.call(Util, 'default') ? Util['default'] : Util; function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { @@ -84,7 +84,7 @@ */ var NAME = 'modal'; - var VERSION = '4.4.1'; + var VERSION = '4.5.0'; var DATA_KEY = 'bs.modal'; var EVENT_KEY = "." + DATA_KEY; var DATA_API_KEY = '.data-api'; @@ -103,50 +103,42 @@ focus: 'boolean', show: 'boolean' }; - var Event = { - HIDE: "hide" + EVENT_KEY, - HIDE_PREVENTED: "hidePrevented" + 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', - STATIC: 'modal-static' - }; - 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' - }; + 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; @@ -170,11 +162,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); @@ -195,11 +187,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; } @@ -222,7 +214,7 @@ return; } - var hideEvent = $.Event(Event.HIDE); + var hideEvent = $.Event(EVENT_HIDE); $(this._element).trigger(hideEvent); if (!this._isShown || hideEvent.isDefaultPrevented()) { @@ -230,7 +222,7 @@ } this._isShown = false; - var transition = $(this._element).hasClass(ClassName.FADE); + var transition = $(this._element).hasClass(CLASS_NAME_FADE); if (transition) { this._isTransitioning = true; @@ -240,10 +232,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); @@ -260,12 +252,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; @@ -284,7 +276,7 @@ ; _proto._getConfig = function _getConfig(config) { - config = _objectSpread2({}, Default, {}, config); + config = _objectSpread2(_objectSpread2({}, Default), config); Util.typeCheckConfig(NAME, config, DefaultType); return config; }; @@ -293,18 +285,18 @@ var _this3 = this; if (this._config.backdrop === 'static') { - var hideEventPrevented = $.Event(Event.HIDE_PREVENTED); + var hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED); $(this._element).trigger(hideEventPrevented); if (hideEventPrevented.defaultPrevented) { return; } - this._element.classList.add(ClassName.STATIC); + this._element.classList.add(CLASS_NAME_STATIC); var modalTransitionDuration = Util.getTransitionDurationFromElement(this._element); $(this._element).one(Util.TRANSITION_END, function () { - _this3._element.classList.remove(ClassName.STATIC); + _this3._element.classList.remove(CLASS_NAME_STATIC); }).emulateTransitionEnd(modalTransitionDuration); this._element.focus(); @@ -316,8 +308,8 @@ _proto._showElement = function _showElement(relatedTarget) { var _this4 = this; - var transition = $(this._element).hasClass(ClassName.FADE); - var modalBody = this._dialog ? this._dialog.querySelector(Selector.MODAL_BODY) : null; + 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 @@ -330,7 +322,7 @@ this._element.setAttribute('aria-modal', true); - if ($(this._dialog).hasClass(ClassName.SCROLLABLE) && modalBody) { + if ($(this._dialog).hasClass(CLASS_NAME_SCROLLABLE) && modalBody) { modalBody.scrollTop = 0; } else { this._element.scrollTop = 0; @@ -340,13 +332,13 @@ 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 }); @@ -370,8 +362,8 @@ _proto._enforceFocus = function _enforceFocus() { var _this5 = this; - $(document).off(Event.FOCUSIN) // Guard against infinite focus loop - .on(Event.FOCUSIN, function (event) { + $(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(); } @@ -381,14 +373,18 @@ _proto._setEscapeEvent = function _setEscapeEvent() { 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(); + + _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); } }; @@ -396,11 +392,11 @@ var _this7 = this; if (this._isShown) { - $(window).on(Event.RESIZE, function (event) { + $(window).on(EVENT_RESIZE, function (event) { return _this7.handleUpdate(event); }); } else { - $(window).off(Event.RESIZE); + $(window).off(EVENT_RESIZE); } }; @@ -416,13 +412,13 @@ this._isTransitioning = false; this._showBackdrop(function () { - $(document.body).removeClass(ClassName.OPEN); + $(document.body).removeClass(CLASS_NAME_OPEN); _this8._resetAdjustments(); _this8._resetScrollbar(); - $(_this8._element).trigger(Event.HIDDEN); + $(_this8._element).trigger(EVENT_HIDDEN); }); }; @@ -436,18 +432,18 @@ _proto._showBackdrop = function _showBackdrop(callback) { 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) { + $(this._element).on(EVENT_CLICK_DISMISS, function (event) { if (_this9._ignoreBackdropClick) { _this9._ignoreBackdropClick = false; return; @@ -464,7 +460,7 @@ Util.reflow(this._backdrop); } - $(this._backdrop).addClass(ClassName.SHOW); + $(this._backdrop).addClass(CLASS_NAME_SHOW); if (!callback) { return; @@ -478,7 +474,7 @@ 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() { _this9._removeBackdrop(); @@ -488,7 +484,7 @@ } }; - 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); @@ -523,7 +519,7 @@ _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(); }; @@ -533,8 +529,8 @@ 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; @@ -553,19 +549,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'); @@ -582,7 +578,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); @@ -594,7 +590,7 @@ return this.each(function () { var data = $(this).data(DATA_KEY); - var _config = _objectSpread2({}, Default, {}, $(this).data(), {}, typeof config === 'object' && config ? config : {}); + var _config = _objectSpread2(_objectSpread2(_objectSpread2({}, Default), $(this).data()), typeof config === 'object' && config ? config : {}); if (!data) { data = new Modal(this, _config); @@ -634,7 +630,7 @@ */ - $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { + $(document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { var _this11 = this; var target; @@ -644,19 +640,19 @@ target = document.querySelector(selector); } - var config = $(target).data(DATA_KEY) ? 'toggle' : _objectSpread2({}, $(target).data(), {}, $(this).data()); + var config = $(target).data(DATA_KEY) ? 'toggle' : _objectSpread2(_objectSpread2({}, $(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 () { + $target.one(EVENT_HIDDEN, function () { if ($(_this11).is(':visible')) { _this11.focus(); } |