mirror of
https://github.com/vladmandic/sdnext.git
synced 2026-01-27 15:02:48 +03:00
22 lines
820 B
JavaScript
22 lines
820 B
JavaScript
async function initDragDrop() {
|
|
log('initDragDrop');
|
|
window.addEventListener('drop', (e) => {
|
|
const target = e.composedPath()[0];
|
|
if (!target.placeholder) return;
|
|
if (target.placeholder.indexOf('Prompt') === -1) return;
|
|
const tabName = getENActiveTab();
|
|
const promptTarget = `${tabName}_prompt_image`;
|
|
const imgParent = gradioApp().getElementById(promptTarget);
|
|
log('dropEvent', target, promptTarget, imgParent);
|
|
const fileInput = imgParent.querySelector('input[type="file"]');
|
|
if (!imgParent || !fileInput) return;
|
|
if ((e.dataTransfer?.files?.length || 0) > 0) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
fileInput.files = e.dataTransfer.files;
|
|
fileInput.dispatchEvent(new Event('change'));
|
|
log('dropEvent files', fileInput.files);
|
|
}
|
|
});
|
|
}
|