[6a3a178] | 1 | /**
|
---|
| 2 | * --------------------------------------------------------------------------
|
---|
| 3 | * Bootstrap (v5.1.3): alert.js
|
---|
| 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
| 5 | * --------------------------------------------------------------------------
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | import { defineJQueryPlugin } from './util/index'
|
---|
| 9 | import EventHandler from './dom/event-handler'
|
---|
| 10 | import BaseComponent from './base-component'
|
---|
| 11 | import { enableDismissTrigger } from './util/component-functions'
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * ------------------------------------------------------------------------
|
---|
| 15 | * Constants
|
---|
| 16 | * ------------------------------------------------------------------------
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | const NAME = 'alert'
|
---|
| 20 | const DATA_KEY = 'bs.alert'
|
---|
| 21 | const EVENT_KEY = `.${DATA_KEY}`
|
---|
| 22 |
|
---|
| 23 | const EVENT_CLOSE = `close${EVENT_KEY}`
|
---|
| 24 | const EVENT_CLOSED = `closed${EVENT_KEY}`
|
---|
| 25 | const CLASS_NAME_FADE = 'fade'
|
---|
| 26 | const CLASS_NAME_SHOW = 'show'
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * ------------------------------------------------------------------------
|
---|
| 30 | * Class Definition
|
---|
| 31 | * ------------------------------------------------------------------------
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | class Alert extends BaseComponent {
|
---|
| 35 | // Getters
|
---|
| 36 |
|
---|
| 37 | static get NAME() {
|
---|
| 38 | return NAME
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | // Public
|
---|
| 42 |
|
---|
| 43 | close() {
|
---|
| 44 | const closeEvent = EventHandler.trigger(this._element, EVENT_CLOSE)
|
---|
| 45 |
|
---|
| 46 | if (closeEvent.defaultPrevented) {
|
---|
| 47 | return
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | this._element.classList.remove(CLASS_NAME_SHOW)
|
---|
| 51 |
|
---|
| 52 | const isAnimated = this._element.classList.contains(CLASS_NAME_FADE)
|
---|
| 53 | this._queueCallback(() => this._destroyElement(), this._element, isAnimated)
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // Private
|
---|
| 57 | _destroyElement() {
|
---|
| 58 | this._element.remove()
|
---|
| 59 | EventHandler.trigger(this._element, EVENT_CLOSED)
|
---|
| 60 | this.dispose()
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | // Static
|
---|
| 64 |
|
---|
| 65 | static jQueryInterface(config) {
|
---|
| 66 | return this.each(function () {
|
---|
| 67 | const data = Alert.getOrCreateInstance(this)
|
---|
| 68 |
|
---|
| 69 | if (typeof config !== 'string') {
|
---|
| 70 | return
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
---|
| 74 | throw new TypeError(`No method named "${config}"`)
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | data[config](this)
|
---|
| 78 | })
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * ------------------------------------------------------------------------
|
---|
| 84 | * Data Api implementation
|
---|
| 85 | * ------------------------------------------------------------------------
|
---|
| 86 | */
|
---|
| 87 |
|
---|
| 88 | enableDismissTrigger(Alert, 'close')
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * ------------------------------------------------------------------------
|
---|
| 92 | * jQuery
|
---|
| 93 | * ------------------------------------------------------------------------
|
---|
| 94 | * add .Alert to jQuery only if jQuery is present
|
---|
| 95 | */
|
---|
| 96 |
|
---|
| 97 | defineJQueryPlugin(Alert)
|
---|
| 98 |
|
---|
| 99 | export default Alert
|
---|