From 18776e43aa6b5a25e94f518a83f36dd1d86093bd Mon Sep 17 00:00:00 2001 From: Kaviilee Date: Tue, 22 Oct 2024 14:44:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96miniprogramHack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/utils.js | 18 ++++++++---------- package.json | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/js/utils.js b/js/utils.js index e343a55..f96b630 100644 --- a/js/utils.js +++ b/js/utils.js @@ -413,20 +413,18 @@ export function miniprogramHack() { document.addEventListener('DOMContentLoaded', function() { // 检查 html 标签是否有 wechat-miniprogram 类 if (document.documentElement.classList.contains('wechat-miniprogram')) { - // 获取所有的 a 标签 - var links = document.getElementsByTagName('a'); - - // 为每个链接添加点击事件监听器 - Array.from(links).forEach(function(link) { - link.addEventListener('click', function(event) { - var href = this.getAttribute('href'); + // 为整个 document 添加一个点击事件监听器 + document.addEventListener('click', function(event) { + // 检查被点击的元素是否是一个链接 + if (event.target.tagName === 'A') { + var href = event.target.getAttribute('href'); // 检查是否是相对链接 var isRelative = !href.startsWith('http://') && !href.startsWith('https://') && !href.startsWith('//'); // 检查是否是jx3box.com域名 var isJx3boxDomain = /jx3box\.com/.test(href); - + // 检查是否是jx3.xoyo.com域名 var isJx3Domain = /jx3\.xoyo\.com/.test(href); @@ -435,13 +433,13 @@ export function miniprogramHack() { // 阻止默认行为 event.preventDefault(); } - }); + } }); } }); - } + export default { resolveImagePath, checkImageLoad, diff --git a/package.json b/package.json index 1032497..abbe31b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jx3box/jx3box-common", - "version": "8.4.0", + "version": "8.4.1", "description": "JX3BOX公共基础模块", "main": "main.js", "repository": {