Created
September 20, 2020 19:46
-
-
Save dgaitsgo/8c5a1424c24c437850a7f411357a0681 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| initImageHoverListeners = (image: HTMLImageElement): void => { | |
| const imageButtonId = 'bai-image-btn-container' | |
| const imageLink = this.getImageContainer(image) | |
| const buttonContainer = this.getButtonContainer('image') | |
| if (imageLink) { | |
| const wrapper = imageLink.parentNode | |
| wrapper?.addEventListener('mouseover', (e) => { | |
| if (e.target === image) { | |
| document.getElementById(imageButtonId)?.remove() | |
| imageLink.style.position = 'relative' | |
| imageLink.prepend(buttonContainer) | |
| window.__loadBAIButton({ | |
| type: 'image', | |
| clickCb: this.safeRequest(() => this.requestAnalyzeImage(image)), | |
| }) | |
| } | |
| }) | |
| wrapper?.addEventListener('mouseout', (e: ChromeEvent) => { | |
| const nextTarget = e?.toElement | |
| const id = nextTarget?.getAttribute('id') | |
| const isButtonContainerChild = nextTarget?.closest('#' + imageButtonId) | |
| if (id !== imageButtonId && !isButtonContainerChild) { | |
| if (e.target === image) { | |
| document.getElementById(imageButtonId)?.remove() | |
| } | |
| } | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment