From 3bb8b6df1cbbd3756a9951bd32e1ec1c55693cb3 Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Fri, 15 Mar 2024 08:53:32 +0100 Subject: [PATCH] Enhance user-friendliness of popup --- service.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/service.js b/service.js index 7bc45f0..cdcc0f6 100644 --- a/service.js +++ b/service.js @@ -517,7 +517,7 @@ class BesService { } } } - popup.hide() + BesPopupEl.hide() } // This function should be able to handle both cases or find a way that works for both. @@ -722,7 +722,7 @@ class BesPopupEl extends HTMLElement {
- +
@@ -767,10 +767,6 @@ class BesPopupEl extends HTMLElement { } } - hide() { - this.classList.remove('show') - } - changeText(text) { this.clear() this.shadowRoot.querySelector('.popup-text').textContent = text @@ -783,14 +779,16 @@ class BesPopupEl extends HTMLElement { replacementBtn.textContent = replacement replacementBtn.classList.add('bes-replacement') replacementBtn.addEventListener('click', () => { - if (allowReplacements) service.replaceText(el, match, replacement) - // TODO: Close popup + if (allowReplacements) { + service.replaceText(el, match, replacement) + BesPopupEl.hide() + } }) replacementDiv.appendChild(replacementBtn) } dragMouseDown(e) { - e = e || window.event + e = e e.preventDefault() this.initialMouseX = e.clientX this.initialMouseY = e.clientY @@ -843,6 +841,13 @@ class BesPopupEl extends HTMLElement { this.isMouseDownRegistered = true } } + + static hide() { + let popups = document.querySelectorAll('bes-popup-el') + popups.forEach(popup => { + popup.classList.remove('show') + }) + } } window.onload = () => {