summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-05-17 09:23:09 +0800
committerEltrac <hi@guhub.cn>2025-05-17 09:23:09 +0800
commit01ef5543ff46c85feaf07e76e03398db7718a0da (patch)
treea185cc20d027fbb27b76938902a4a20955ce3646 /assets
parentee8f25324164c845a7767d93b31ebd48571a3607 (diff)
perf: remove unnecessary fancybox helper script
Former-commit-id: 1df5202592eb9ea3d46bc347511c1e68ae5bbeeb
Diffstat (limited to 'assets')
-rw-r--r--assets/js/fancybox.js39
1 files changed, 0 insertions, 39 deletions
diff --git a/assets/js/fancybox.js b/assets/js/fancybox.js
deleted file mode 100644
index 15b70e48..00000000
--- a/assets/js/fancybox.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * fancybox.js
- * - initialize fancybox library
- * - automatically wrap images
- */
-
-document.addEventListener("DOMContentLoaded", function () {
- document
- .querySelectorAll(".markdown-body img:not(figure img, .no-fancybox)")
- .forEach((img) => {
- if (img.closest("figure")) return; // 跳过已经在 <figure> 内的 <img>
-
- let src = img.getAttribute("src");
- let alt = img.getAttribute("alt") || ""; // 获取 alt 作为 title
-
- // 创建 <a> 标签包裹 <img>
- let link = document.createElement("a");
- link.setAttribute("href", src);
- link.setAttribute("data-fancybox", "gallery"); // Fancybox 组
- link.setAttribute("data-caption", alt); // 设置 title
- link.setAttribute("aria-label", alt); // 辅助功能优化
-
- // 创建 <figcaption> 并添加 <h4>
- let figcaption = document.createElement("figcaption");
- let captionTitle = document.createElement("h4");
- captionTitle.textContent = alt;
- figcaption.appendChild(captionTitle);
-
- // 创建 <figure> 并包裹 <a> + <figcaption>
- let figure = document.createElement("figure");
- figure.appendChild(link);
- figure.appendChild(figcaption);
-
- // 替换原始 img
- img.parentNode.insertBefore(figure, img);
- link.appendChild(img); // 将 img 插入 <a>
- });
-});
-Fancybox.bind("[data-fancybox]");