forked from deblan/side_menu
33 lines
736 B
JavaScript
33 lines
736 B
JavaScript
const waitContainer = async (selector) => {
|
|
return new Promise((resolve) => {
|
|
const container = document.querySelector(selector)
|
|
|
|
if (container) {
|
|
return resolve(selector, container)
|
|
}
|
|
|
|
setTimeout(() => {
|
|
waitContainer(selector)
|
|
}, 50)
|
|
})
|
|
}
|
|
|
|
const createElement = (tagName, attributes) => {
|
|
const element = document.createElement(tagName)
|
|
|
|
if (typeof attributes === 'object') {
|
|
for (let i in attributes) {
|
|
if (i === 'text') {
|
|
element.textContent = attributes[i]
|
|
} else if (i === 'html') {
|
|
element.innerHTML = attributes[i]
|
|
} else {
|
|
element.setAttribute(i, attributes[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
return element
|
|
}
|
|
|
|
export { waitContainer, createElement }
|