1 | /*!
|
---|
2 | * Bootstrap toast.js v5.3.3 (https://getbootstrap.com/)
|
---|
3 | * Copyright 2011-2024 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
---|
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
5 | */
|
---|
6 | (function (global, factory) {
|
---|
7 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./base-component.js'), require('./dom/event-handler.js'), require('./util/component-functions.js'), require('./util/index.js')) :
|
---|
8 | typeof define === 'function' && define.amd ? define(['./base-component', './dom/event-handler', './util/component-functions', './util/index'], factory) :
|
---|
9 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Toast = factory(global.BaseComponent, global.EventHandler, global.ComponentFunctions, global.Index));
|
---|
10 | })(this, (function (BaseComponent, EventHandler, componentFunctions_js, index_js) { 'use strict';
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * --------------------------------------------------------------------------
|
---|
14 | * Bootstrap toast.js
|
---|
15 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
16 | * --------------------------------------------------------------------------
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Constants
|
---|
22 | */
|
---|
23 |
|
---|
24 | const NAME = 'toast';
|
---|
25 | const DATA_KEY = 'bs.toast';
|
---|
26 | const EVENT_KEY = `.${DATA_KEY}`;
|
---|
27 | const EVENT_MOUSEOVER = `mouseover${EVENT_KEY}`;
|
---|
28 | const EVENT_MOUSEOUT = `mouseout${EVENT_KEY}`;
|
---|
29 | const EVENT_FOCUSIN = `focusin${EVENT_KEY}`;
|
---|
30 | const EVENT_FOCUSOUT = `focusout${EVENT_KEY}`;
|
---|
31 | const EVENT_HIDE = `hide${EVENT_KEY}`;
|
---|
32 | const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
|
---|
33 | const EVENT_SHOW = `show${EVENT_KEY}`;
|
---|
34 | const EVENT_SHOWN = `shown${EVENT_KEY}`;
|
---|
35 | const CLASS_NAME_FADE = 'fade';
|
---|
36 | const CLASS_NAME_HIDE = 'hide'; // @deprecated - kept here only for backwards compatibility
|
---|
37 | const CLASS_NAME_SHOW = 'show';
|
---|
38 | const CLASS_NAME_SHOWING = 'showing';
|
---|
39 | const DefaultType = {
|
---|
40 | animation: 'boolean',
|
---|
41 | autohide: 'boolean',
|
---|
42 | delay: 'number'
|
---|
43 | };
|
---|
44 | const Default = {
|
---|
45 | animation: true,
|
---|
46 | autohide: true,
|
---|
47 | delay: 5000
|
---|
48 | };
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Class definition
|
---|
52 | */
|
---|
53 |
|
---|
54 | class Toast extends BaseComponent {
|
---|
55 | constructor(element, config) {
|
---|
56 | super(element, config);
|
---|
57 | this._timeout = null;
|
---|
58 | this._hasMouseInteraction = false;
|
---|
59 | this._hasKeyboardInteraction = false;
|
---|
60 | this._setListeners();
|
---|
61 | }
|
---|
62 |
|
---|
63 | // Getters
|
---|
64 | static get Default() {
|
---|
65 | return Default;
|
---|
66 | }
|
---|
67 | static get DefaultType() {
|
---|
68 | return DefaultType;
|
---|
69 | }
|
---|
70 | static get NAME() {
|
---|
71 | return NAME;
|
---|
72 | }
|
---|
73 |
|
---|
74 | // Public
|
---|
75 | show() {
|
---|
76 | const showEvent = EventHandler.trigger(this._element, EVENT_SHOW);
|
---|
77 | if (showEvent.defaultPrevented) {
|
---|
78 | return;
|
---|
79 | }
|
---|
80 | this._clearTimeout();
|
---|
81 | if (this._config.animation) {
|
---|
82 | this._element.classList.add(CLASS_NAME_FADE);
|
---|
83 | }
|
---|
84 | const complete = () => {
|
---|
85 | this._element.classList.remove(CLASS_NAME_SHOWING);
|
---|
86 | EventHandler.trigger(this._element, EVENT_SHOWN);
|
---|
87 | this._maybeScheduleHide();
|
---|
88 | };
|
---|
89 | this._element.classList.remove(CLASS_NAME_HIDE); // @deprecated
|
---|
90 | index_js.reflow(this._element);
|
---|
91 | this._element.classList.add(CLASS_NAME_SHOW, CLASS_NAME_SHOWING);
|
---|
92 | this._queueCallback(complete, this._element, this._config.animation);
|
---|
93 | }
|
---|
94 | hide() {
|
---|
95 | if (!this.isShown()) {
|
---|
96 | return;
|
---|
97 | }
|
---|
98 | const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE);
|
---|
99 | if (hideEvent.defaultPrevented) {
|
---|
100 | return;
|
---|
101 | }
|
---|
102 | const complete = () => {
|
---|
103 | this._element.classList.add(CLASS_NAME_HIDE); // @deprecated
|
---|
104 | this._element.classList.remove(CLASS_NAME_SHOWING, CLASS_NAME_SHOW);
|
---|
105 | EventHandler.trigger(this._element, EVENT_HIDDEN);
|
---|
106 | };
|
---|
107 | this._element.classList.add(CLASS_NAME_SHOWING);
|
---|
108 | this._queueCallback(complete, this._element, this._config.animation);
|
---|
109 | }
|
---|
110 | dispose() {
|
---|
111 | this._clearTimeout();
|
---|
112 | if (this.isShown()) {
|
---|
113 | this._element.classList.remove(CLASS_NAME_SHOW);
|
---|
114 | }
|
---|
115 | super.dispose();
|
---|
116 | }
|
---|
117 | isShown() {
|
---|
118 | return this._element.classList.contains(CLASS_NAME_SHOW);
|
---|
119 | }
|
---|
120 |
|
---|
121 | // Private
|
---|
122 |
|
---|
123 | _maybeScheduleHide() {
|
---|
124 | if (!this._config.autohide) {
|
---|
125 | return;
|
---|
126 | }
|
---|
127 | if (this._hasMouseInteraction || this._hasKeyboardInteraction) {
|
---|
128 | return;
|
---|
129 | }
|
---|
130 | this._timeout = setTimeout(() => {
|
---|
131 | this.hide();
|
---|
132 | }, this._config.delay);
|
---|
133 | }
|
---|
134 | _onInteraction(event, isInteracting) {
|
---|
135 | switch (event.type) {
|
---|
136 | case 'mouseover':
|
---|
137 | case 'mouseout':
|
---|
138 | {
|
---|
139 | this._hasMouseInteraction = isInteracting;
|
---|
140 | break;
|
---|
141 | }
|
---|
142 | case 'focusin':
|
---|
143 | case 'focusout':
|
---|
144 | {
|
---|
145 | this._hasKeyboardInteraction = isInteracting;
|
---|
146 | break;
|
---|
147 | }
|
---|
148 | }
|
---|
149 | if (isInteracting) {
|
---|
150 | this._clearTimeout();
|
---|
151 | return;
|
---|
152 | }
|
---|
153 | const nextElement = event.relatedTarget;
|
---|
154 | if (this._element === nextElement || this._element.contains(nextElement)) {
|
---|
155 | return;
|
---|
156 | }
|
---|
157 | this._maybeScheduleHide();
|
---|
158 | }
|
---|
159 | _setListeners() {
|
---|
160 | EventHandler.on(this._element, EVENT_MOUSEOVER, event => this._onInteraction(event, true));
|
---|
161 | EventHandler.on(this._element, EVENT_MOUSEOUT, event => this._onInteraction(event, false));
|
---|
162 | EventHandler.on(this._element, EVENT_FOCUSIN, event => this._onInteraction(event, true));
|
---|
163 | EventHandler.on(this._element, EVENT_FOCUSOUT, event => this._onInteraction(event, false));
|
---|
164 | }
|
---|
165 | _clearTimeout() {
|
---|
166 | clearTimeout(this._timeout);
|
---|
167 | this._timeout = null;
|
---|
168 | }
|
---|
169 |
|
---|
170 | // Static
|
---|
171 | static jQueryInterface(config) {
|
---|
172 | return this.each(function () {
|
---|
173 | const data = Toast.getOrCreateInstance(this, config);
|
---|
174 | if (typeof config === 'string') {
|
---|
175 | if (typeof data[config] === 'undefined') {
|
---|
176 | throw new TypeError(`No method named "${config}"`);
|
---|
177 | }
|
---|
178 | data[config](this);
|
---|
179 | }
|
---|
180 | });
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Data API implementation
|
---|
186 | */
|
---|
187 |
|
---|
188 | componentFunctions_js.enableDismissTrigger(Toast);
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * jQuery
|
---|
192 | */
|
---|
193 |
|
---|
194 | index_js.defineJQueryPlugin(Toast);
|
---|
195 |
|
---|
196 | return Toast;
|
---|
197 |
|
---|
198 | }));
|
---|
199 | //# sourceMappingURL=toast.js.map
|
---|