瀏覽代碼

Fix dragging to/from firefox

missionfloyd 1 年之前
父節點
當前提交
3da13f0cc9
共有 1 個文件被更改,包括 4 次插入5 次删除
  1. 4 5
      javascript/dragdrop.js

+ 4 - 5
javascript/dragdrop.js

@@ -57,7 +57,7 @@ function eventHasFiles(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) {
@@ -96,13 +96,12 @@ window.document.addEventListener('drop', e => {
         const files = e.dataTransfer.files;
         const fileInput = imgParent.querySelector('input[type="file"]');
         const urlInput = urlParent.querySelector('textarea');
-        if (files && fileInput) {
-            fileInput.files = files;
-            fileInput.dispatchEvent(new Event('change'));
-        }
         if (url && urlInput) {
             urlInput.value = url;
             urlInput.dispatchEvent(new Event('input'));
+        } else if (files && fileInput) {
+            fileInput.files = files;
+            fileInput.dispatchEvent(new Event('change'));
         }
     }