class MessageElement extends HTMLElement { constructor() { super(); } onClose(containerClass) { if (containerClass) { document.querySelector(`.${containerClass}`).innerHTML = ""; } } connectedCallback() { const message = this.getAttribute("data-message") || ""; const type = this.getAttribute("data-type") || "message"; const isClose = (this.getAttribute("data-isclose") || "false") === "true"; const containerClass = this.getAttribute("data-container-class") || ""; const elem = document.createElement("div"); elem.innerHTML = `
${message} ${ isClose ? `` : "" }
`; this.appendChild(elem); if (isClose) { const closeButton = this.querySelector(".popup__close"); closeButton.addEventListener("click", () => this.onClose(containerClass)); } } } window.customElements.define("message-element", MessageElement);