From e9ba2d42d6c13bc3f8763c6ccd00fff2519b3152 Mon Sep 17 00:00:00 2001 From: Connum Date: Wed, 21 Sep 2022 00:28:03 +0200 Subject: fix image replacement via clipboard paste or drag and drop on PNG Info tab --- javascript/dragdrop.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'javascript/dragdrop.js') diff --git a/javascript/dragdrop.js b/javascript/dragdrop.js index 29e26766..0fb74dba 100644 --- a/javascript/dragdrop.js +++ b/javascript/dragdrop.js @@ -10,13 +10,34 @@ function dropReplaceImage( imgWrap, files ) { } imgWrap.querySelector('.modify-upload button + button, .touch-none + div button + button')?.click(); - window.requestAnimationFrame( () => { + const callback = () => { const fileInput = imgWrap.querySelector('input[type="file"]'); if ( fileInput ) { fileInput.files = files; fileInput.dispatchEvent(new Event('change')); } - }); + }; + + if ( imgWrap.closest('#pnginfo_image') ) { + // special treatment for PNG Info tab, wait for fetch request to finish + const oldFetch = window.fetch; + window.fetch = async (input, options) => { + const response = await oldFetch(input, options); + if ( 'api/predict/' === input ) { + const content = await response.text(); + window.fetch = oldFetch; + window.requestAnimationFrame( () => callback() ); + return new Response(content, { + status: response.status, + statusText: response.statusText, + headers: response.headers + }) + } + return response; + }; + } else { + window.requestAnimationFrame( () => callback() ); + } } function pressClearBtn(hoverElems) { -- cgit v1.2.3 From b5693699b8460008ca92544b42f6bc394078ee4d Mon Sep 17 00:00:00 2001 From: Connum Date: Wed, 21 Sep 2022 01:57:11 +0200 Subject: Revert "Reset image input when dragover new image" This reverts commit 9035afbab5e1285cfc7ad39c1e17374973842ae9. --- javascript/dragdrop.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'javascript/dragdrop.js') diff --git a/javascript/dragdrop.js b/javascript/dragdrop.js index 0fb74dba..c01f66e2 100644 --- a/javascript/dragdrop.js +++ b/javascript/dragdrop.js @@ -40,15 +40,6 @@ 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"]'); @@ -57,13 +48,7 @@ window.document.addEventListener('dragover', e => { } e.stopPropagation(); e.preventDefault(); - - if (e.dataTransfer) - e.dataTransfer.dropEffect = 'copy'; - - //If is gr.Interface clear image on hover - if (target.previousElementSibling) - pressClearBtn(target.previousElementSibling) + e.dataTransfer.dropEffect = 'copy'; }); window.document.addEventListener('drop', e => { -- cgit v1.2.3