diff options
| author | Eltrac <hi@guhub.cn> | 2025-05-17 09:23:09 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-05-17 09:23:09 +0800 |
| commit | 1df5202592eb9ea3d46bc347511c1e68ae5bbeeb (patch) | |
| tree | 9d4aa6ef0a13fce9fff49a96feea2e5164e2a683 /assets/js | |
| parent | 9267f11dbdbb1eb073865f06babfd0909837fe6f (diff) | |
perf: remove unnecessary fancybox helper script
Diffstat (limited to 'assets/js')
| -rw-r--r-- | assets/js/fancybox.js | 39 |
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]"); |
