source: imaps-frontend/node_modules/bootstrap/js/src/alert.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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