0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-03 15:24:19 +01:00
Bootstrap/js/dist/alert.js

101 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-11-13 07:41:12 +01:00
/*!
2022-05-13 08:07:23 +02:00
* Bootstrap alert.js v5.2.0-beta1 (https://getbootstrap.com/)
* Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 20:50:01 +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) {
2022-05-13 08:07:23 +02:00
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./util/index'), require('./dom/event-handler'), require('./base-component'), require('./util/component-functions')) :
typeof define === 'function' && define.amd ? define(['./util/index', './dom/event-handler', './base-component', './util/component-functions'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.Index, global.EventHandler, global.BaseComponent, global.ComponentFunctions));
})(this, (function (index, EventHandler, BaseComponent, componentFunctions) { 'use strict';
2018-07-24 02:51:14 +02:00
2021-10-05 17:50:18 +02:00
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
2020-09-14 17:12:06 +02:00
2021-10-05 17:50:18 +02:00
const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
2021-08-04 17:41:51 +02:00
/**
* --------------------------------------------------------------------------
2022-05-13 08:07:23 +02:00
* Bootstrap (v5.2.0-beta1): alert.js
2021-03-23 17:26:54 +01:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
2020-12-03 15:18:59 +01:00
/**
* Constants
*/
2021-03-23 17:26:54 +01:00
const NAME = 'alert';
const DATA_KEY = 'bs.alert';
const EVENT_KEY = `.${DATA_KEY}`;
const EVENT_CLOSE = `close${EVENT_KEY}`;
const EVENT_CLOSED = `closed${EVENT_KEY}`;
const CLASS_NAME_FADE = 'fade';
const CLASS_NAME_SHOW = 'show';
2019-10-08 08:39:10 +02:00
/**
2022-05-13 08:07:23 +02:00
* Class definition
2019-10-08 08:39:10 +02:00
*/
2021-10-05 17:50:18 +02:00
class Alert extends BaseComponent__default.default {
2021-03-23 17:26:54 +01:00
// Getters
static get NAME() {
return NAME;
2021-03-23 17:26:54 +01:00
} // Public
2015-05-07 21:48:22 +02:00
2015-08-13 06:12:03 +02:00
2021-08-04 17:41:51 +02:00
close() {
2021-10-05 17:50:18 +02:00
const closeEvent = EventHandler__default.default.trigger(this._element, EVENT_CLOSE);
2015-05-07 21:48:22 +02:00
2021-08-04 17:41:51 +02:00
if (closeEvent.defaultPrevented) {
2018-11-13 07:41:12 +01:00
return;
}
2016-10-10 02:26:51 +02:00
2021-08-04 17:41:51 +02:00
this._element.classList.remove(CLASS_NAME_SHOW);
2017-09-30 23:28:03 +02:00
2021-08-04 17:41:51 +02:00
const isAnimated = this._element.classList.contains(CLASS_NAME_FADE);
2015-05-07 21:48:22 +02:00
2021-08-04 17:41:51 +02:00
this._queueCallback(() => this._destroyElement(), this._element, isAnimated);
} // Private
2015-05-07 21:48:22 +02:00
2016-11-01 05:36:10 +01:00
2021-08-04 17:41:51 +02:00
_destroyElement() {
this._element.remove();
2015-05-07 21:48:22 +02:00
2021-10-05 17:50:18 +02:00
EventHandler__default.default.trigger(this._element, EVENT_CLOSED);
2021-08-04 17:41:51 +02:00
this.dispose();
2019-01-04 17:29:45 +01:00
} // Static
2016-10-10 02:26:51 +02:00
2021-03-23 17:26:54 +01:00
static jQueryInterface(config) {
2018-11-13 07:41:12 +01:00
return this.each(function () {
const data = Alert.getOrCreateInstance(this);
2016-10-10 02:26:51 +02:00
2021-08-04 17:41:51 +02:00
if (typeof config !== 'string') {
return;
2018-11-13 07:41:12 +01:00
}
2016-10-10 02:26:51 +02:00
2021-08-04 17:41:51 +02:00
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
throw new TypeError(`No method named "${config}"`);
2018-11-13 07:41:12 +01:00
}
2017-09-30 23:28:03 +02:00
2021-08-04 17:41:51 +02:00
data[config](this);
});
2021-03-23 17:26:54 +01:00
}
2015-05-07 21:48:22 +02:00
2021-03-23 17:26:54 +01:00
}
2018-11-13 07:41:12 +01:00
/**
2022-05-13 08:07:23 +02:00
* Data API implementation
2018-11-13 07:41:12 +01:00
*/
2015-05-07 21:48:22 +02:00
2022-05-13 08:07:23 +02:00
componentFunctions.enableDismissTrigger(Alert, 'close');
2018-11-13 07:41:12 +01:00
/**
* jQuery
*/
2017-09-30 23:28:03 +02:00
2022-05-13 08:07:23 +02:00
index.defineJQueryPlugin(Alert);
2015-05-07 21:48:22 +02:00
return Alert;
2018-07-24 02:51:14 +02:00
2021-10-05 17:50:18 +02:00
}));
2018-07-24 02:51:14 +02:00
//# sourceMappingURL=alert.js.map