diff options
Diffstat (limited to 'js/dist/alert.js')
-rw-r--r-- | js/dist/alert.js | 147 |
1 files changed, 115 insertions, 32 deletions
diff --git a/js/dist/alert.js b/js/dist/alert.js index 2a2e157edc..d163cd4ce6 100644 --- a/js/dist/alert.js +++ b/js/dist/alert.js @@ -4,13 +4,14 @@ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/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.Alert = factory(global.jQuery, global.Util)); -}(this, function ($, Util) { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/eventHandler.js'), require('./dom/selectorEngine.js')) : + typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/eventHandler.js', './dom/selectorEngine.js'], factory) : + (global = global || self, global.Alert = factory(global.Data, global.EventHandler, global.SelectorEngine)); +}(this, function (Data, EventHandler, SelectorEngine) { 'use strict'; - $ = $ && $.hasOwnProperty('default') ? $['default'] : $; - Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util; + Data = Data && Data.hasOwnProperty('default') ? Data['default'] : Data; + EventHandler = EventHandler && EventHandler.hasOwnProperty('default') ? EventHandler['default'] : EventHandler; + SelectorEngine = SelectorEngine && SelectorEngine.hasOwnProperty('default') ? SelectorEngine['default'] : SelectorEngine; function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { @@ -29,6 +30,76 @@ } /** + * -------------------------------------------------------------------------- + * Bootstrap (v4.3.1): util/index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * -------------------------------------------------------------------------- + */ + var MILLISECONDS_MULTIPLIER = 1000; + var TRANSITION_END = 'transitionend'; + var jQuery = window.jQuery; // Shoutout AngusCroll (https://goo.gl/pxwQGp) + + var getSelectorFromElement = function getSelectorFromElement(element) { + var selector = element.getAttribute('data-target'); + + if (!selector || selector === '#') { + var hrefAttr = element.getAttribute('href'); + selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : ''; + } + + try { + return document.querySelector(selector) ? selector : null; + } catch (err) { + return null; + } + }; + + var getTransitionDurationFromElement = function getTransitionDurationFromElement(element) { + if (!element) { + return 0; + } // Get transition-duration of the element + + + var _window$getComputedSt = window.getComputedStyle(element), + transitionDuration = _window$getComputedSt.transitionDuration, + transitionDelay = _window$getComputedSt.transitionDelay; + + var floatTransitionDuration = parseFloat(transitionDuration); + var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found + + if (!floatTransitionDuration && !floatTransitionDelay) { + return 0; + } // If multiple durations are defined, take the first + + + transitionDuration = transitionDuration.split(',')[0]; + transitionDelay = transitionDelay.split(',')[0]; + return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER; + }; + + var triggerTransitionEnd = function triggerTransitionEnd(element) { + element.dispatchEvent(new Event(TRANSITION_END)); + }; + + var emulateTransitionEnd = function emulateTransitionEnd(element, duration) { + var called = false; + var durationPadding = 5; + var emulatedDuration = duration + durationPadding; + + function listener() { + called = true; + element.removeEventListener(TRANSITION_END, listener); + } + + element.addEventListener(TRANSITION_END, listener); + setTimeout(function () { + if (!called) { + triggerTransitionEnd(element); + } + }, emulatedDuration); + }; + + /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ @@ -39,11 +110,10 @@ var DATA_KEY = 'bs.alert'; var EVENT_KEY = "." + DATA_KEY; var DATA_API_KEY = '.data-api'; - var JQUERY_NO_CONFLICT = $.fn[NAME]; var Selector = { DISMISS: '[data-dismiss="alert"]' }; - var Event = { + var Event$1 = { CLOSE: "close" + EVENT_KEY, CLOSED: "closed" + EVENT_KEY, CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY @@ -65,6 +135,10 @@ function () { function Alert(element) { this._element = element; + + if (this._element) { + Data.setData(element, DATA_KEY, this); + } } // Getters @@ -80,7 +154,7 @@ var customEvent = this._triggerCloseEvent(rootElement); - if (customEvent.isDefaultPrevented()) { + if (customEvent === null || customEvent.defaultPrevented) { return; } @@ -88,62 +162,63 @@ }; _proto.dispose = function dispose() { - $.removeData(this._element, DATA_KEY); + Data.removeData(this._element, DATA_KEY); this._element = null; } // Private ; _proto._getRootElement = function _getRootElement(element) { - var selector = Util.getSelectorFromElement(element); + var selector = getSelectorFromElement(element); var parent = false; if (selector) { - parent = document.querySelector(selector); + parent = SelectorEngine.findOne(selector); } if (!parent) { - parent = $(element).closest("." + ClassName.ALERT)[0]; + parent = SelectorEngine.closest(element, "." + ClassName.ALERT); } return parent; }; _proto._triggerCloseEvent = function _triggerCloseEvent(element) { - var closeEvent = $.Event(Event.CLOSE); - $(element).trigger(closeEvent); - return closeEvent; + return EventHandler.trigger(element, Event$1.CLOSE); }; _proto._removeElement = function _removeElement(element) { var _this = this; - $(element).removeClass(ClassName.SHOW); + element.classList.remove(ClassName.SHOW); - if (!$(element).hasClass(ClassName.FADE)) { + if (!element.classList.contains(ClassName.FADE)) { this._destroyElement(element); return; } - var transitionDuration = Util.getTransitionDurationFromElement(element); - $(element).one(Util.TRANSITION_END, function (event) { + var transitionDuration = getTransitionDurationFromElement(element); + EventHandler.one(element, TRANSITION_END, function (event) { return _this._destroyElement(element, event); - }).emulateTransitionEnd(transitionDuration); + }); + emulateTransitionEnd(element, transitionDuration); }; _proto._destroyElement = function _destroyElement(element) { - $(element).detach().trigger(Event.CLOSED).remove(); + if (element.parentNode) { + element.parentNode.removeChild(element); + } + + EventHandler.trigger(element, Event$1.CLOSED); } // Static ; Alert._jQueryInterface = function _jQueryInterface(config) { return this.each(function () { - var $element = $(this); - var data = $element.data(DATA_KEY); + var data = Data.getData(this, DATA_KEY); if (!data) { data = new Alert(this); - $element.data(DATA_KEY, data); } if (config === 'close') { @@ -162,6 +237,10 @@ }; }; + Alert._getInstance = function _getInstance(element) { + return Data.getData(element, DATA_KEY); + }; + _createClass(Alert, null, [{ key: "VERSION", get: function get() { @@ -178,20 +257,24 @@ */ - $(document).on(Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert())); + EventHandler.on(document, Event$1.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert())); /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ + * add .alert to jQuery only if jQuery is present */ - $.fn[NAME] = Alert._jQueryInterface; - $.fn[NAME].Constructor = Alert; + if (typeof jQuery !== 'undefined') { + var JQUERY_NO_CONFLICT = jQuery.fn[NAME]; + jQuery.fn[NAME] = Alert._jQueryInterface; + jQuery.fn[NAME].Constructor = Alert; - $.fn[NAME].noConflict = function () { - $.fn[NAME] = JQUERY_NO_CONFLICT; - return Alert._jQueryInterface; - }; + jQuery.fn[NAME].noConflict = function () { + jQuery.fn[NAME] = JQUERY_NO_CONFLICT; + return Alert._jQueryInterface; + }; + } return Alert; |