diff options
Diffstat (limited to 'assets/javascripts/bootstrap/modal.js')
-rw-r--r-- | assets/javascripts/bootstrap/modal.js | 112 |
1 files changed, 69 insertions, 43 deletions
diff --git a/assets/javascripts/bootstrap/modal.js b/assets/javascripts/bootstrap/modal.js index f2e2f74..c6113e9 100644 --- a/assets/javascripts/bootstrap/modal.js +++ b/assets/javascripts/bootstrap/modal.js @@ -6,7 +6,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.5): modal.js + * Bootstrap (v4.0.0-alpha.6): modal.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ @@ -20,7 +20,7 @@ var Modal = function ($) { */ var NAME = 'modal'; - var VERSION = '4.0.0-alpha.5'; + var VERSION = '4.0.0-alpha.6'; var DATA_KEY = 'bs.modal'; var EVENT_KEY = '.' + DATA_KEY; var DATA_API_KEY = '.data-api'; @@ -62,14 +62,14 @@ var Modal = function ($) { BACKDROP: 'modal-backdrop', OPEN: 'modal-open', FADE: 'fade', - IN: 'in' + SHOW: 'show' }; var Selector = { DIALOG: '.modal-dialog', DATA_TOGGLE: '[data-toggle="modal"]', DATA_DISMISS: '[data-dismiss="modal"]', - FIXED_CONTENT: '.navbar-fixed-top, .navbar-fixed-bottom, .is-fixed' + FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top' }; /** @@ -89,6 +89,7 @@ var Modal = function ($) { this._isShown = false; this._isBodyOverflowing = false; this._ignoreBackdropClick = false; + this._isTransitioning = false; this._originalBodyPadding = 0; this._scrollbarWidth = 0; } @@ -104,6 +105,13 @@ var Modal = function ($) { Modal.prototype.show = function show(relatedTarget) { var _this = this; + if (this._isTransitioning) { + throw new Error('Modal is transitioning'); + } + + if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) { + this._isTransitioning = true; + } var showEvent = $.Event(Event.SHOW, { relatedTarget: relatedTarget }); @@ -124,7 +132,9 @@ var Modal = function ($) { this._setEscapeEvent(); this._setResizeEvent(); - $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, $.proxy(this.hide, this)); + $(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) { @@ -134,16 +144,28 @@ var Modal = function ($) { }); }); - this._showBackdrop($.proxy(this._showElement, this, relatedTarget)); + this._showBackdrop(function () { + return _this._showElement(relatedTarget); + }); }; Modal.prototype.hide = function hide(event) { + var _this2 = this; + if (event) { event.preventDefault(); } - var hideEvent = $.Event(Event.HIDE); + if (this._isTransitioning) { + throw new Error('Modal is transitioning'); + } + + var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE); + if (transition) { + this._isTransitioning = true; + } + var hideEvent = $.Event(Event.HIDE); $(this._element).trigger(hideEvent); if (!this._isShown || hideEvent.isDefaultPrevented()) { @@ -157,14 +179,15 @@ var Modal = function ($) { $(document).off(Event.FOCUSIN); - $(this._element).removeClass(ClassName.IN); + $(this._element).removeClass(ClassName.SHOW); $(this._element).off(Event.CLICK_DISMISS); $(this._dialog).off(Event.MOUSEDOWN_DISMISS); - if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) { - - $(this._element).one(Util.TRANSITION_END, $.proxy(this._hideModal, this)).emulateTransitionEnd(TRANSITION_DURATION); + if (transition) { + $(this._element).one(Util.TRANSITION_END, function (event) { + return _this2._hideModal(event); + }).emulateTransitionEnd(TRANSITION_DURATION); } else { this._hideModal(); } @@ -173,10 +196,7 @@ var Modal = function ($) { Modal.prototype.dispose = function dispose() { $.removeData(this._element, DATA_KEY); - $(window).off(EVENT_KEY); - $(document).off(EVENT_KEY); - $(this._element).off(EVENT_KEY); - $(this._backdrop).off(EVENT_KEY); + $(window, document, this._element, this._backdrop).off(EVENT_KEY); this._config = null; this._element = null; @@ -198,7 +218,7 @@ var Modal = function ($) { }; Modal.prototype._showElement = function _showElement(relatedTarget) { - var _this2 = this; + var _this3 = this; var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE); @@ -215,7 +235,7 @@ var Modal = function ($) { Util.reflow(this._element); } - $(this._element).addClass(ClassName.IN); + $(this._element).addClass(ClassName.SHOW); if (this._config.focus) { this._enforceFocus(); @@ -226,10 +246,11 @@ var Modal = function ($) { }); var transitionComplete = function transitionComplete() { - if (_this2._config.focus) { - _this2._element.focus(); + if (_this3._config.focus) { + _this3._element.focus(); } - $(_this2._element).trigger(shownEvent); + _this3._isTransitioning = false; + $(_this3._element).trigger(shownEvent); }; if (transition) { @@ -240,23 +261,23 @@ var Modal = function ($) { }; Modal.prototype._enforceFocus = function _enforceFocus() { - var _this3 = this; + var _this4 = this; $(document).off(Event.FOCUSIN) // guard against infinite focus loop .on(Event.FOCUSIN, function (event) { - if (document !== event.target && _this3._element !== event.target && !$(_this3._element).has(event.target).length) { - _this3._element.focus(); + if (document !== event.target && _this4._element !== event.target && !$(_this4._element).has(event.target).length) { + _this4._element.focus(); } }); }; Modal.prototype._setEscapeEvent = function _setEscapeEvent() { - var _this4 = this; + var _this5 = this; if (this._isShown && this._config.keyboard) { $(this._element).on(Event.KEYDOWN_DISMISS, function (event) { if (event.which === ESCAPE_KEYCODE) { - _this4.hide(); + _this5.hide(); } }); } else if (!this._isShown) { @@ -265,23 +286,28 @@ var Modal = function ($) { }; Modal.prototype._setResizeEvent = function _setResizeEvent() { + var _this6 = this; + if (this._isShown) { - $(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this)); + $(window).on(Event.RESIZE, function (event) { + return _this6._handleUpdate(event); + }); } else { $(window).off(Event.RESIZE); } }; Modal.prototype._hideModal = function _hideModal() { - var _this5 = this; + var _this7 = this; this._element.style.display = 'none'; this._element.setAttribute('aria-hidden', 'true'); + this._isTransitioning = false; this._showBackdrop(function () { $(document.body).removeClass(ClassName.OPEN); - _this5._resetAdjustments(); - _this5._resetScrollbar(); - $(_this5._element).trigger(Event.HIDDEN); + _this7._resetAdjustments(); + _this7._resetScrollbar(); + $(_this7._element).trigger(Event.HIDDEN); }); }; @@ -293,7 +319,7 @@ var Modal = function ($) { }; Modal.prototype._showBackdrop = function _showBackdrop(callback) { - var _this6 = this; + var _this8 = this; var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : ''; @@ -310,17 +336,17 @@ var Modal = function ($) { $(this._backdrop).appendTo(document.body); $(this._element).on(Event.CLICK_DISMISS, function (event) { - if (_this6._ignoreBackdropClick) { - _this6._ignoreBackdropClick = false; + if (_this8._ignoreBackdropClick) { + _this8._ignoreBackdropClick = false; return; } if (event.target !== event.currentTarget) { return; } - if (_this6._config.backdrop === 'static') { - _this6._element.focus(); + if (_this8._config.backdrop === 'static') { + _this8._element.focus(); } else { - _this6.hide(); + _this8.hide(); } }); @@ -328,7 +354,7 @@ var Modal = function ($) { Util.reflow(this._backdrop); } - $(this._backdrop).addClass(ClassName.IN); + $(this._backdrop).addClass(ClassName.SHOW); if (!callback) { return; @@ -341,10 +367,10 @@ var Modal = function ($) { $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION); } else if (!this._isShown && this._backdrop) { - $(this._backdrop).removeClass(ClassName.IN); + $(this._backdrop).removeClass(ClassName.SHOW); var callbackRemove = function callbackRemove() { - _this6._removeBackdrop(); + _this8._removeBackdrop(); if (callback) { callback(); } @@ -460,7 +486,7 @@ var Modal = function ($) { */ $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { - var _this7 = this; + var _this9 = this; var target = void 0; var selector = Util.getSelectorFromElement(this); @@ -471,7 +497,7 @@ var Modal = function ($) { var config = $(target).data(DATA_KEY) ? 'toggle' : $.extend({}, $(target).data(), $(this).data()); - if (this.tagName === 'A') { + if (this.tagName === 'A' || this.tagName === 'AREA') { event.preventDefault(); } @@ -482,8 +508,8 @@ var Modal = function ($) { } $target.one(Event.HIDDEN, function () { - if ($(_this7).is(':visible')) { - _this7.focus(); + if ($(_this9).is(':visible')) { + _this9.focus(); } }); }); |