diff options
author | trufty <trufty@gmail.com> | 2022-09-20 18:59:34 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2022-09-20 20:30:36 +0000 |
commit | 9035afbab5e1285cfc7ad39c1e17374973842ae9 (patch) | |
tree | 43798c8be5427f721a6c15647c8a9481dd996735 /javascript/dragdrop.js | |
parent | 19a75d38d79f4c754510c4745440f0c60d89cb78 (diff) | |
download | stable-diffusion-webui-gfx803-9035afbab5e1285cfc7ad39c1e17374973842ae9.tar.gz stable-diffusion-webui-gfx803-9035afbab5e1285cfc7ad39c1e17374973842ae9.tar.bz2 stable-diffusion-webui-gfx803-9035afbab5e1285cfc7ad39c1e17374973842ae9.zip |
Reset image input when dragover new image
Diffstat (limited to 'javascript/dragdrop.js')
-rw-r--r-- | javascript/dragdrop.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/javascript/dragdrop.js b/javascript/dragdrop.js index 4cd05151..29e26766 100644 --- a/javascript/dragdrop.js +++ b/javascript/dragdrop.js @@ -19,6 +19,15 @@ function dropReplaceImage( imgWrap, files ) { }); } +function pressClearBtn(hoverElems) { + //Find all buttons hovering over the image box + let btns = Array.from(hoverElems.querySelectorAll("button")) + + //Press the last btn which will be the X button + if (btns.length) + btns[btns.length-1].click() +} + window.document.addEventListener('dragover', e => { const target = e.composedPath()[0]; const imgWrap = target.closest('[data-testid="image"]'); @@ -27,7 +36,13 @@ window.document.addEventListener('dragover', e => { } e.stopPropagation(); e.preventDefault(); - e.dataTransfer.dropEffect = 'copy'; + + if (e.dataTransfer) + e.dataTransfer.dropEffect = 'copy'; + + //If is gr.Interface clear image on hover + if (target.previousElementSibling) + pressClearBtn(target.previousElementSibling) }); window.document.addEventListener('drop', e => { |