0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-05 23:46:20 +01:00
Bootstrap/js/dist/alert.js

180 lines
5.9 KiB
JavaScript
Raw Normal View History

2018-11-13 07:41:12 +01:00
/*!
2020-10-13 17:38:30 +02:00
* Bootstrap alert.js v4.5.3 (https://getbootstrap.com/)
2020-05-12 18:53:07 +02:00
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-08-04 18:24:33 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2018-11-13 07:41:12 +01:00
*/
2018-07-24 02:51:14 +02:00
(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) :
2020-08-04 18:24:33 +02:00
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.jQuery, global.Util));
2019-11-26 18:12:00 +01:00
}(this, (function ($, Util) { 'use strict';
2018-07-24 02:51:14 +02:00
2020-10-13 17:38:30 +02:00
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var $__default = /*#__PURE__*/_interopDefaultLegacy($);
var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
2018-07-24 02:51:14 +02:00
2020-08-04 18:24:33 +02:00
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); } }
2017-09-06 06:05:12 +02:00
2020-08-04 18:24:33 +02:00
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2018-11-13 07:41:12 +01:00
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'alert';
2020-10-13 17:38:30 +02:00
var VERSION = '4.5.3';
2018-11-13 07:41:12 +01:00
var DATA_KEY = 'bs.alert';
var EVENT_KEY = "." + DATA_KEY;
var DATA_API_KEY = '.data-api';
2020-10-13 17:38:30 +02:00
var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
2020-05-12 18:53:07 +02:00
var SELECTOR_DISMISS = '[data-dismiss="alert"]';
var EVENT_CLOSE = "close" + EVENT_KEY;
var EVENT_CLOSED = "closed" + EVENT_KEY;
var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
var CLASS_NAME_ALERT = 'alert';
var CLASS_NAME_FADE = 'fade';
var CLASS_NAME_SHOW = 'show';
2019-11-26 18:12:00 +01:00
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
2020-05-12 18:53:07 +02:00
var Alert = /*#__PURE__*/function () {
2018-11-13 07:41:12 +01:00
function Alert(element) {
this._element = element;
} // Getters
2017-09-30 23:28:03 +02:00
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
var _proto = Alert.prototype;
2015-08-13 06:12:03 +02:00
2018-11-13 07:41:12 +01:00
// Public
_proto.close = function close(element) {
var rootElement = this._element;
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
if (element) {
rootElement = this._getRootElement(element);
}
2015-05-08 02:07:38 +02:00
2018-11-13 07:41:12 +01:00
var customEvent = this._triggerCloseEvent(rootElement);
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
if (customEvent.isDefaultPrevented()) {
return;
}
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
this._removeElement(rootElement);
};
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
_proto.dispose = function dispose() {
2020-10-13 17:38:30 +02:00
$__default['default'].removeData(this._element, DATA_KEY);
2018-11-13 07:41:12 +01:00
this._element = null;
2019-01-04 17:29:45 +01:00
} // Private
;
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
_proto._getRootElement = function _getRootElement(element) {
2020-10-13 17:38:30 +02:00
var selector = Util__default['default'].getSelectorFromElement(element);
2018-11-13 07:41:12 +01:00
var parent = false;
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
if (selector) {
parent = document.querySelector(selector);
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
if (!parent) {
2020-10-13 17:38:30 +02:00
parent = $__default['default'](element).closest("." + CLASS_NAME_ALERT)[0];
2018-11-13 07:41:12 +01:00
}
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
return parent;
};
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
_proto._triggerCloseEvent = function _triggerCloseEvent(element) {
2020-10-13 17:38:30 +02:00
var closeEvent = $__default['default'].Event(EVENT_CLOSE);
$__default['default'](element).trigger(closeEvent);
2018-11-13 07:41:12 +01:00
return closeEvent;
};
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
_proto._removeElement = function _removeElement(element) {
var _this = this;
2016-11-01 05:36:10 +01:00
2020-10-13 17:38:30 +02:00
$__default['default'](element).removeClass(CLASS_NAME_SHOW);
2015-05-07 21:48:22 +02:00
2020-10-13 17:38:30 +02:00
if (!$__default['default'](element).hasClass(CLASS_NAME_FADE)) {
2018-11-13 07:41:12 +01:00
this._destroyElement(element);
2015-08-19 05:28:28 +02:00
2018-11-13 07:41:12 +01:00
return;
}
2015-05-07 21:48:22 +02:00
2020-10-13 17:38:30 +02:00
var transitionDuration = Util__default['default'].getTransitionDurationFromElement(element);
$__default['default'](element).one(Util__default['default'].TRANSITION_END, function (event) {
2018-11-13 07:41:12 +01:00
return _this._destroyElement(element, event);
}).emulateTransitionEnd(transitionDuration);
};
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
_proto._destroyElement = function _destroyElement(element) {
2020-10-13 17:38:30 +02:00
$__default['default'](element).detach().trigger(EVENT_CLOSED).remove();
2019-01-04 17:29:45 +01:00
} // Static
;
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
Alert._jQueryInterface = function _jQueryInterface(config) {
return this.each(function () {
2020-10-13 17:38:30 +02:00
var $element = $__default['default'](this);
2018-11-13 07:41:12 +01:00
var data = $element.data(DATA_KEY);
2017-09-06 06:05:12 +02:00
2018-11-13 07:41:12 +01:00
if (!data) {
data = new Alert(this);
$element.data(DATA_KEY, data);
}
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
if (config === 'close') {
data[config](this);
}
});
};
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
Alert._handleDismiss = function _handleDismiss(alertInstance) {
return function (event) {
if (event) {
event.preventDefault();
}
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
alertInstance.close(this);
2017-09-30 23:28:03 +02:00
};
2018-11-13 07:41:12 +01:00
};
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
_createClass(Alert, null, [{
key: "VERSION",
get: function get() {
return VERSION;
}
}]);
2015-05-07 21:48:22 +02:00
2018-11-13 07:41:12 +01:00
return Alert;
}();
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
*/
2015-05-07 21:48:22 +02:00
2020-10-13 17:38:30 +02:00
$__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert._handleDismiss(new Alert()));
2018-11-13 07:41:12 +01:00
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
2017-09-30 23:28:03 +02:00
2020-10-13 17:38:30 +02:00
$__default['default'].fn[NAME] = Alert._jQueryInterface;
$__default['default'].fn[NAME].Constructor = Alert;
2018-07-24 02:51:14 +02:00
2020-10-13 17:38:30 +02:00
$__default['default'].fn[NAME].noConflict = function () {
$__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
2018-11-13 07:41:12 +01:00
return Alert._jQueryInterface;
};
2015-05-07 21:48:22 +02:00
return Alert;
2018-07-24 02:51:14 +02:00
2019-11-26 18:12:00 +01:00
})));
2018-07-24 02:51:14 +02:00
//# sourceMappingURL=alert.js.map