diff --git a/images/turn-off-svgrepo-com.svg b/images/turn-off-svgrepo-com.svg new file mode 100644 index 0000000..6c31e9c --- /dev/null +++ b/images/turn-off-svgrepo-com.svg @@ -0,0 +1,7 @@ + + + + + + 1105 + \ No newline at end of file diff --git a/service.js b/service.js index dded9ca..cad462a 100644 --- a/service.js +++ b/service.js @@ -60,11 +60,13 @@ class BesService { false ) if (this.timer) clearTimeout(this.timer) - service.abortController.abort() + this.abortController.abort() besServices = besServices.filter(item => item !== this) this.hostElement.spellcheck = this.originalSpellcheck this.correctionPanel.remove() this.scrollPanel.remove() + this.statusDiv.remove() + this.statusIcon.remove() } /** @@ -223,6 +225,11 @@ class BesService { statusDiv.appendChild(statusIcon) this.setStatusDivPosition(hostElement, statusDiv) hostElement.parentNode.insertBefore(statusDiv, hostElement.nextSibling) + const statusPopup = document.createElement('bes-popup-status-el') + document.body.appendChild(statusPopup) + statusDiv.addEventListener('click', e => { + this.handleStatusClick(e, statusPopup) + }) return { correctionPanel, scrollPanel, statusDiv, statusIcon } } @@ -377,6 +384,10 @@ class BesService { this.statusIcon.classList.add(status) } + handleStatusClick(e, popup) { + popup.show(e.clientX, e.clientY, this) + } + /** * Tests if given element is block element. * @@ -1016,6 +1027,134 @@ class BesPopupEl extends HTMLElement { } } +class BesStatusPopup extends HTMLElement { + constructor() { + super() + this.attachShadow({ mode: 'open' }) + } + + render() { + this.shadowRoot.innerHTML = ` + +
+
+
Besana
+ +
+
+ + Če želite izključiti preverjanje pravopisa, kliknite na gumb. + + +
+
+ ` + } + + show(x, y, service) { + y = y + 20 + this.style.position = 'fixed' + this.style.left = `${x}px` + this.style.top = `${y}px` + this.style.display = 'block' + + const viewportWidth = window.innerWidth + const viewportHeight = window.innerHeight + const popupWidth = this.offsetWidth + const popupHeight = this.offsetHeight + const maxPositionX = viewportWidth - popupWidth + const maxPositionY = viewportHeight - popupHeight + const positionX = this.offsetLeft + const positionY = this.offsetTop + if (positionX > maxPositionX) { + this.style.left = maxPositionX + 'px' + } + if (positionY > maxPositionY) { + this.style.top = maxPositionY + 'px' + } + this.disableButton = this.shadowRoot.querySelector('.bes-service-btn') + if (service) { + this.disableButton.addEventListener('click', () => this.disable(service)) + } + this.classList.add('show') + } + + connectedCallback() { + this.render() + } + + disable(service) { + service.unregister() + BesStatusPopup.hide() + } + + static hide() { + const popup = document.querySelector('bes-popup-status-el.show') + popup?.classList?.remove('show') + } +} + window.onload = () => { document.querySelectorAll('.bes-service').forEach(hostElement => { if (hostElement.tagName === 'TEXTAREA') BesTAService.register(hostElement) @@ -1055,3 +1194,4 @@ window.onscroll = () => { } customElements.define('bes-popup-el', BesPopupEl) +customElements.define('bes-popup-status-el', BesStatusPopup)