aboutsummaryrefslogtreecommitdiff
path: root/js/src/toast.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/toast.js')
-rw-r--r--js/src/toast.js62
1 files changed, 26 insertions, 36 deletions
diff --git a/js/src/toast.js b/js/src/toast.js
index c45721c8f..d5d9c0ee0 100644
--- a/js/src/toast.js
+++ b/js/src/toast.js
@@ -1,19 +1,14 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.1.3): toast.js
+ * Bootstrap toast.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
-import {
- defineJQueryPlugin,
- reflow,
- typeCheckConfig
-} from './util/index'
-import EventHandler from './dom/event-handler'
-import Manipulator from './dom/manipulator'
-import BaseComponent from './base-component'
-import { enableDismissTrigger } from './util/component-functions'
+import BaseComponent from './base-component.js'
+import EventHandler from './dom/event-handler.js'
+import { enableDismissTrigger } from './util/component-functions.js'
+import { defineJQueryPlugin, reflow } from './util/index.js'
/**
* Constants
@@ -55,9 +50,8 @@ const Default = {
class Toast extends BaseComponent {
constructor(element, config) {
- super(element)
+ super(element, config)
- this._config = this._getConfig(config)
this._timeout = null
this._hasMouseInteraction = false
this._hasKeyboardInteraction = false
@@ -65,14 +59,14 @@ class Toast extends BaseComponent {
}
// Getters
- static get DefaultType() {
- return DefaultType
- }
-
static get Default() {
return Default
}
+ static get DefaultType() {
+ return DefaultType
+ }
+
static get NAME() {
return NAME
}
@@ -100,14 +94,13 @@ class Toast extends BaseComponent {
this._element.classList.remove(CLASS_NAME_HIDE) // @deprecated
reflow(this._element)
- this._element.classList.add(CLASS_NAME_SHOW)
- this._element.classList.add(CLASS_NAME_SHOWING)
+ this._element.classList.add(CLASS_NAME_SHOW, CLASS_NAME_SHOWING)
this._queueCallback(complete, this._element, this._config.animation)
}
hide() {
- if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
+ if (!this.isShown()) {
return
}
@@ -119,8 +112,7 @@ class Toast extends BaseComponent {
const complete = () => {
this._element.classList.add(CLASS_NAME_HIDE) // @deprecated
- this._element.classList.remove(CLASS_NAME_SHOWING)
- this._element.classList.remove(CLASS_NAME_SHOW)
+ this._element.classList.remove(CLASS_NAME_SHOWING, CLASS_NAME_SHOW)
EventHandler.trigger(this._element, EVENT_HIDDEN)
}
@@ -131,26 +123,19 @@ class Toast extends BaseComponent {
dispose() {
this._clearTimeout()
- if (this._element.classList.contains(CLASS_NAME_SHOW)) {
+ if (this.isShown()) {
this._element.classList.remove(CLASS_NAME_SHOW)
}
super.dispose()
}
- // Private
- _getConfig(config) {
- config = {
- ...Default,
- ...Manipulator.getDataAttributes(this._element),
- ...(typeof config === 'object' && config ? config : {})
- }
-
- typeCheckConfig(NAME, config, this.constructor.DefaultType)
-
- return config
+ isShown() {
+ return this._element.classList.contains(CLASS_NAME_SHOW)
}
+ // Private
+
_maybeScheduleHide() {
if (!this._config.autohide) {
return
@@ -168,15 +153,20 @@ class Toast extends BaseComponent {
_onInteraction(event, isInteracting) {
switch (event.type) {
case 'mouseover':
- case 'mouseout':
+ case 'mouseout': {
this._hasMouseInteraction = isInteracting
break
+ }
+
case 'focusin':
- case 'focusout':
+ case 'focusout': {
this._hasKeyboardInteraction = isInteracting
break
- default:
+ }
+
+ default: {
break
+ }
}
if (isInteracting) {