Skip to content

Commit e043dc9

Browse files
committed
【修复】优化图片和 SVG 的点击事件处理
- 将图片和 SVG 的点击事件处理逻辑从文档级事件监听中分离 - 优化了图片和 SVG 的打开方式,优先打开源链接 - 调整了事件处理的顺序,提高了用户体验
1 parent 4cae978 commit e043dc9

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

index.html

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22

33
<html>
4-
<markdown-html version="1.18.3" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
4+
<markdown-html version="1.18.4" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
55
license="CC BY-SA 4.0 International"></markdown-html>
66

77
<head>
@@ -667,20 +667,6 @@
667667
});
668668
//// 点击事件委托
669669
document.addEventListener('click', function (event) {
670-
const imgOrSvg = event.target.closest('.content img, .content svg');
671-
if (imgOrSvg) {
672-
const url = imgOrSvg.getAttribute('src') || imgOrSvg.getAttribute('xlink:href');
673-
if (url) {
674-
window.open(url, '_blank');
675-
event.preventDefault();
676-
} else {
677-
const newWindow = window.open('', '_blank');
678-
newWindow.document.write(imgOrSvg.outerHTML);
679-
newWindow.document.close();
680-
event.preventDefault();
681-
}
682-
return;
683-
}
684670
if (event.target.closest('.back-btn')) {
685671
window.history.back();
686672
} else if (event.target.closest('.refresh-btn')) {
@@ -711,6 +697,17 @@
711697
window.open(href, '_blank');
712698
event.preventDefault();
713699
}
700+
} else if (event.target.closest('.content img, .content svg')) {
701+
const url = event.target.getAttribute('src') || event.target.getAttribute('xlink:href');
702+
if (url) {
703+
window.open(url, '_blank');
704+
event.preventDefault();
705+
} else {
706+
const newWindow = window.open('', '_blank');
707+
newWindow.document.write(imgOrSvg.outerHTML);
708+
newWindow.document.close();
709+
event.preventDefault();
710+
}
714711
}
715712
});
716713
//// 文档内容加载完毕时触发

0 commit comments

Comments
 (0)