Fix dragging to/from firefox

This commit is contained in:
missionfloyd 2024-03-16 15:46:29 -06:00
parent 8eaa7e9f04
commit 3da13f0cc9
1 changed files with 4 additions and 5 deletions

View File

@ -57,7 +57,7 @@ function eventHasFiles(e) {
} }
function getEventUrl(e) { function getEventUrl(e) {
return e?.dataTransfer?.getData('URL') || e?.dataTransfer?.getData('text/html')?.match(/(?:src|href)=["'](.*?)["']/)?.[1]; return e.dataTransfer?.getData('text/uri-list') || e.dataTransfer?.getData('text/plain');
} }
function dragDropTargetIsPrompt(target) { function dragDropTargetIsPrompt(target) {
@ -96,13 +96,12 @@ window.document.addEventListener('drop', e => {
const files = e.dataTransfer.files; const files = e.dataTransfer.files;
const fileInput = imgParent.querySelector('input[type="file"]'); const fileInput = imgParent.querySelector('input[type="file"]');
const urlInput = urlParent.querySelector('textarea'); const urlInput = urlParent.querySelector('textarea');
if (files && fileInput) {
fileInput.files = files;
fileInput.dispatchEvent(new Event('change'));
}
if (url && urlInput) { if (url && urlInput) {
urlInput.value = url; urlInput.value = url;
urlInput.dispatchEvent(new Event('input')); urlInput.dispatchEvent(new Event('input'));
} else if (files && fileInput) {
fileInput.files = files;
fileInput.dispatchEvent(new Event('change'));
} }
} }