Sfoglia il codice sorgente

【修复】优化图片和 SVG 的点击事件处理

- 将图片和 SVG 的点击事件处理逻辑从文档级事件监听中分离
- 优化了图片和 SVG 的打开方式,优先打开源链接
- 调整了事件处理的顺序,提高了用户体验
PJ568 1 anno fa
parent
commit
6d34017bc9
1 ha cambiato i file con 12 aggiunte e 15 eliminazioni
  1. 12 15
      index.html

+ 12 - 15
index.html

@@ -1,7 +1,7 @@
 <!doctype html>
 
 <html>
-<markdown-html version="1.18.3" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
+<markdown-html version="1.18.4" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
   license="CC BY-SA 4.0 International"></markdown-html>
 
 <head>
@@ -667,20 +667,6 @@
       });
       //// 点击事件委托
       document.addEventListener('click', function (event) {
-        const imgOrSvg = event.target.closest('.content img, .content svg');
-        if (imgOrSvg) {
-          const url = imgOrSvg.getAttribute('src') || imgOrSvg.getAttribute('xlink:href');
-          if (url) {
-            window.open(url, '_blank');
-            event.preventDefault();
-          } else {
-            const newWindow = window.open('', '_blank');
-            newWindow.document.write(imgOrSvg.outerHTML);
-            newWindow.document.close();
-            event.preventDefault();
-          }
-          return;
-        }
         if (event.target.closest('.back-btn')) {
           window.history.back();
         } else if (event.target.closest('.refresh-btn')) {
@@ -711,6 +697,17 @@
             window.open(href, '_blank');
             event.preventDefault();
           }
+        } else if (event.target.closest('.content img, .content svg')) {
+          const url = event.target.getAttribute('src') || event.target.getAttribute('xlink:href');
+          if (url) {
+            window.open(url, '_blank');
+            event.preventDefault();
+          } else {
+            const newWindow = window.open('', '_blank');
+            newWindow.document.write(imgOrSvg.outerHTML);
+            newWindow.document.close();
+            event.preventDefault();
+          }
         }
       });
       //// 文档内容加载完毕时触发