mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-17 19:21:23 +03:00
Refactor js code
This commit is contained in:
+11
-11
@@ -19,8 +19,6 @@ const NAME = 'toast'
|
|||||||
const DATA_KEY = 'bs.toast'
|
const DATA_KEY = 'bs.toast'
|
||||||
const EVENT_KEY = `.${DATA_KEY}`
|
const EVENT_KEY = `.${DATA_KEY}`
|
||||||
|
|
||||||
const CLASS_PROGRESS_BAR = '.toast-progress'
|
|
||||||
|
|
||||||
const EVENT_MOUSEOVER = `mouseover${EVENT_KEY}`
|
const EVENT_MOUSEOVER = `mouseover${EVENT_KEY}`
|
||||||
const EVENT_MOUSEOUT = `mouseout${EVENT_KEY}`
|
const EVENT_MOUSEOUT = `mouseout${EVENT_KEY}`
|
||||||
const EVENT_FOCUSIN = `focusin${EVENT_KEY}`
|
const EVENT_FOCUSIN = `focusin${EVENT_KEY}`
|
||||||
@@ -31,10 +29,13 @@ const EVENT_SHOW = `show${EVENT_KEY}`
|
|||||||
const EVENT_SHOWN = `shown${EVENT_KEY}`
|
const EVENT_SHOWN = `shown${EVENT_KEY}`
|
||||||
|
|
||||||
const CLASS_NAME_FADE = 'fade'
|
const CLASS_NAME_FADE = 'fade'
|
||||||
const CLASS_NAME_HIDE = 'hide' // @deprecated - kept here only for backwards compatibility
|
const CLASS_NAME_HIDE = 'hide' // TODO:v6: @deprecated - kept here only for backwards compatibility
|
||||||
const CLASS_NAME_SHOW = 'show'
|
const CLASS_NAME_SHOW = 'show'
|
||||||
const CLASS_NAME_SHOWING = 'showing'
|
const CLASS_NAME_SHOWING = 'showing'
|
||||||
|
|
||||||
|
const CLASS_PROGRESS_BAR = '.toast-progress'
|
||||||
|
const CLASS_NAME_PROGRESS_BAR_ANIMATED = 'animated'
|
||||||
|
|
||||||
const DefaultType = {
|
const DefaultType = {
|
||||||
animation: 'boolean',
|
animation: 'boolean',
|
||||||
autohide: 'boolean',
|
autohide: 'boolean',
|
||||||
@@ -148,7 +149,7 @@ class Toast extends BaseComponent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this._toggleProgressBar(this._config.delay)
|
this._toggleProgressBar(true)
|
||||||
this._timeout = setTimeout(() => {
|
this._timeout = setTimeout(() => {
|
||||||
this.hide()
|
this.hide()
|
||||||
}, this._config.delay)
|
}, this._config.delay)
|
||||||
@@ -190,24 +191,23 @@ class Toast extends BaseComponent {
|
|||||||
|
|
||||||
_clearTimeout() {
|
_clearTimeout() {
|
||||||
clearTimeout(this._timeout)
|
clearTimeout(this._timeout)
|
||||||
this._toggleProgressBar(null)
|
this._toggleProgressBar(false)
|
||||||
this._timeout = null
|
this._timeout = null
|
||||||
}
|
}
|
||||||
|
|
||||||
_toggleProgressBar(time) {
|
_toggleProgressBar(enable) {
|
||||||
const progressBarElement = SelectorEngine.findOne(CLASS_PROGRESS_BAR, this._element)
|
const progressBarElement = SelectorEngine.findOne(CLASS_PROGRESS_BAR, this._element)
|
||||||
if (!progressBarElement) {
|
if (!progressBarElement) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time) {
|
if (enable) {
|
||||||
progressBarElement.classList.add('animated')
|
progressBarElement.classList.add(CLASS_NAME_PROGRESS_BAR_ANIMATED)
|
||||||
progressBarElement.style.animationDuration = `${time}ms`
|
progressBarElement.style.animationDuration = `${this._config.delay}ms`
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBarElement.classList.remove('animated')
|
progressBarElement.classList.remove(CLASS_NAME_PROGRESS_BAR_ANIMATED)
|
||||||
reflow(progressBarElement)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static
|
// Static
|
||||||
|
|||||||
Reference in New Issue
Block a user