diff options
Diffstat (limited to 'js/dist/toast.js')
-rw-r--r-- | js/dist/toast.js | 145 |
1 files changed, 115 insertions, 30 deletions
diff --git a/js/dist/toast.js b/js/dist/toast.js index b1be5fc377..20461fd17e 100644 --- a/js/dist/toast.js +++ b/js/dist/toast.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.Toast = 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/manipulator.js')) : + typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/eventHandler.js', './dom/manipulator.js'], factory) : + (global = global || self, global.Toast = factory(global.Data, global.EventHandler, global.Manipulator)); +}(this, function (Data, EventHandler, Manipulator) { '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; + Manipulator = Manipulator && Manipulator.hasOwnProperty('default') ? Manipulator['default'] : Manipulator; function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { @@ -63,6 +64,81 @@ } /** + * -------------------------------------------------------------------------- + * 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 toType = function toType(obj) { + return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase(); + }; + + 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 isElement = function isElement(obj) { + return (obj[0] || obj).nodeType; + }; + + 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); + }; + + var typeCheckConfig = function typeCheckConfig(componentName, config, configTypes) { + Object.keys(configTypes).forEach(function (property) { + var expectedTypes = configTypes[property]; + var value = config[property]; + var valueType = value && isElement(value) ? 'element' : toType(value); + + if (!new RegExp(expectedTypes).test(valueType)) { + throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\".")); + } + }); + }; + + /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ @@ -72,8 +148,7 @@ var VERSION = '4.3.1'; var DATA_KEY = 'bs.toast'; var EVENT_KEY = "." + DATA_KEY; - var JQUERY_NO_CONFLICT = $.fn[NAME]; - var Event = { + var Event$1 = { CLICK_DISMISS: "click.dismiss" + EVENT_KEY, HIDE: "hide" + EVENT_KEY, HIDDEN: "hidden" + EVENT_KEY, @@ -115,6 +190,8 @@ this._timeout = null; this._setListeners(); + + Data.setData(element, DATA_KEY, this); } // Getters @@ -124,7 +201,7 @@ _proto.show = function show() { var _this = this; - $(this._element).trigger(Event.SHOW); + EventHandler.trigger(this._element, Event$1.SHOW); if (this._config.animation) { this._element.classList.add(ClassName.FADE); @@ -135,7 +212,7 @@ _this._element.classList.add(ClassName.SHOW); - $(_this._element).trigger(Event.SHOWN); + EventHandler.trigger(_this._element, Event$1.SHOWN); if (_this._config.autohide) { _this.hide(); @@ -147,8 +224,9 @@ this._element.classList.add(ClassName.SHOWING); if (this._config.animation) { - var transitionDuration = Util.getTransitionDurationFromElement(this._element); - $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); + var transitionDuration = getTransitionDurationFromElement(this._element); + EventHandler.one(this._element, TRANSITION_END, complete); + emulateTransitionEnd(this._element, transitionDuration); } else { complete(); } @@ -161,7 +239,7 @@ return; } - $(this._element).trigger(Event.HIDE); + EventHandler.trigger(this._element, Event$1.HIDE); if (withoutTimeout) { this._close(); @@ -180,23 +258,23 @@ this._element.classList.remove(ClassName.SHOW); } - $(this._element).off(Event.CLICK_DISMISS); - $.removeData(this._element, DATA_KEY); + EventHandler.off(this._element, Event$1.CLICK_DISMISS); + Data.removeData(this._element, DATA_KEY); this._element = null; this._config = null; } // Private ; _proto._getConfig = function _getConfig(config) { - config = _objectSpread({}, Default, $(this._element).data(), typeof config === 'object' && config ? config : {}); - Util.typeCheckConfig(NAME, config, this.constructor.DefaultType); + config = _objectSpread({}, Default, Manipulator.getDataAttributes(this._element), typeof config === 'object' && config ? config : {}); + typeCheckConfig(NAME, config, this.constructor.DefaultType); return config; }; _proto._setListeners = function _setListeners() { var _this3 = this; - $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function () { + EventHandler.on(this._element, Event$1.CLICK_DISMISS, Selector.DATA_DISMISS, function () { return _this3.hide(true); }); }; @@ -207,14 +285,15 @@ var complete = function complete() { _this4._element.classList.add(ClassName.HIDE); - $(_this4._element).trigger(Event.HIDDEN); + EventHandler.trigger(_this4._element, Event$1.HIDDEN); }; this._element.classList.remove(ClassName.SHOW); if (this._config.animation) { - var transitionDuration = Util.getTransitionDurationFromElement(this._element); - $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); + var transitionDuration = getTransitionDurationFromElement(this._element); + EventHandler.one(this._element, TRANSITION_END, complete); + emulateTransitionEnd(this._element, transitionDuration); } else { complete(); } @@ -223,14 +302,12 @@ Toast._jQueryInterface = function _jQueryInterface(config) { return this.each(function () { - var $element = $(this); - var data = $element.data(DATA_KEY); + var data = Data.getData(this, DATA_KEY); var _config = typeof config === 'object' && config; if (!data) { data = new Toast(this, _config); - $element.data(DATA_KEY, data); } if (typeof config === 'string') { @@ -243,6 +320,10 @@ }); }; + Toast._getInstance = function _getInstance(element) { + return Data.getData(element, DATA_KEY); + }; + _createClass(Toast, null, [{ key: "VERSION", get: function get() { @@ -266,16 +347,20 @@ * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ + * add .toast to jQuery only if jQuery is present */ - $.fn[NAME] = Toast._jQueryInterface; - $.fn[NAME].Constructor = Toast; + if (typeof jQuery !== 'undefined') { + var JQUERY_NO_CONFLICT = jQuery.fn[NAME]; + jQuery.fn[NAME] = Toast._jQueryInterface; + jQuery.fn[NAME].Constructor = Toast; - $.fn[NAME].noConflict = function () { - $.fn[NAME] = JQUERY_NO_CONFLICT; - return Toast._jQueryInterface; - }; + jQuery.fn[NAME].noConflict = function () { + jQuery.fn[NAME] = JQUERY_NO_CONFLICT; + return Toast._jQueryInterface; + }; + } return Toast; |