mirror of
https://git.hmsn.ink/kospo/helptalk/api.git
synced 2026-03-20 02:12:38 +09:00
first
This commit is contained in:
75
sample/dev/talk/bundle/awesome-notifications-3.1.1/elem.js
Normal file
75
sample/dev/talk/bundle/awesome-notifications-3.1.1/elem.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import {
|
||||
eConsts
|
||||
} from "./constants.js"
|
||||
import {global} from '../../js/module/variable.js'
|
||||
|
||||
export default class {
|
||||
constructor(parent, id, klass, style, options) {
|
||||
this.newNode = document.createElement('div')
|
||||
if (id) this.newNode.id = id
|
||||
if (klass) this.newNode.className = klass
|
||||
if (style) this.newNode.style.cssText = style
|
||||
this.parent = parent
|
||||
this.options = options
|
||||
}
|
||||
beforeInsert() {}
|
||||
afterInsert() {}
|
||||
insert() {
|
||||
this.beforeInsert()
|
||||
this.el = this.parent.appendChild(this.newNode)
|
||||
this.afterInsert()
|
||||
return this
|
||||
}
|
||||
|
||||
replace(el) {
|
||||
if (!this.getElement()) return
|
||||
return this.beforeDelete().then(() => {
|
||||
this.updateType(el.type)
|
||||
this.parent.replaceChild(el.newNode, this.el)
|
||||
this.el = this.getElement(el.newNode)
|
||||
this.afterInsert()
|
||||
return this
|
||||
})
|
||||
}
|
||||
|
||||
beforeDelete(el = this.el) {
|
||||
let timeLeft = 0
|
||||
if (this.start) {
|
||||
timeLeft = this.options.minDurations[this.type] + this.start - Date.now()
|
||||
if (timeLeft < 0) timeLeft = 0
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
el.classList.add(eConsts.klass.hiding)
|
||||
setTimeout(resolve, this.options.animationDuration)
|
||||
}, timeLeft)
|
||||
})
|
||||
}
|
||||
|
||||
delete(el = this.el) {
|
||||
if (!this.getElement(el)) return null
|
||||
return this.beforeDelete(el).then(() => {
|
||||
el.remove()
|
||||
this.afterDelete()
|
||||
})
|
||||
}
|
||||
afterDelete() {}
|
||||
|
||||
getElement(el = this.el) {
|
||||
if (!el) return null
|
||||
return global.shadowRoot.getElementById(el.id)
|
||||
}
|
||||
|
||||
addEvent(name, func) {
|
||||
this.el.addEventListener(name, func)
|
||||
}
|
||||
|
||||
toggleClass(klass) {
|
||||
this.el.classList.toggle(klass)
|
||||
}
|
||||
updateType(type) {
|
||||
this.type = type
|
||||
this.duration = this.options.duration(this.type)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user