mirror of
https://github.com/vladmandic/sdnext.git
synced 2026-01-27 15:02:48 +03:00
26 lines
1003 B
JavaScript
26 lines
1003 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 tab = get_tab_index('tabs');
|
|
let promptTarget = '';
|
|
if (tab === 0) promptTarget = 'txt2img_prompt_image';
|
|
else if (tab === 1) promptTarget = 'img2img_prompt_image';
|
|
else if (tab === 2) promptTarget = 'control_prompt_image';
|
|
else if (tab === 3) promptTarget = 'video_prompt_image';
|
|
else return;
|
|
const imgParent = gradioApp().getElementById(promptTarget);
|
|
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);
|
|
}
|
|
});
|
|
}
|