UNPKG

xx-common

Version:

the functions of yd common

38 lines (33 loc) 1.09 kB
const global = { toast: (msg: any, duration = 2500) => { let messageRoot = document.createElement("div"); messageRoot.className = "yd-message"; let message = document.createElement("span"); if (message.insertAdjacentText) { message.insertAdjacentText("afterbegin", msg); } else { message.appendChild(msg); } if (messageRoot.insertAdjacentElement) messageRoot.insertAdjacentElement("afterbegin", message); else messageRoot.appendChild(message); let rootId = document.getElementById("app"); let ydMessage = document.querySelector(".yd-message"); if (ydMessage) ydMessage.remove(); if (!rootId) return; if (rootId.insertAdjacentElement) { rootId.insertAdjacentElement("afterbegin", messageRoot); } else { rootId.appendChild(messageRoot); } setTimeout(function () { ydMessage = document.querySelector(".yd-message"); if (ydMessage) ydMessage.remove(); }, duration); }, }; export default () => { if (typeof window.global == "undefined") { window.global = global; } };