From e4cc625c33ecd2992dcf60f408417c3067b4fa2b Mon Sep 17 00:00:00 2001
From: Aiden Bai <aiden.bai05@gmail.com>
Date: Tue, 03 May 2022 16:34:27 +0000
Subject: [PATCH] Add future note about init function
---
assets/js/popover.js | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/assets/js/popover.js b/assets/js/popover.js
index 83cdc03..460c245 100644
--- a/assets/js/popover.js
+++ b/assets/js/popover.js
@@ -1,5 +1,5 @@
function htmlToElement(html) {
- const template = document.createElement('template')
+ const template = document.createElement("template")
html = html.trim()
template.innerHTML = html
return template.content.firstChild
@@ -7,12 +7,12 @@
function initPopover(baseURL) {
const basePath = baseURL.replace(window.location.origin, "")
- document.addEventListener("DOMContentLoaded", () => {
- fetchData.then(({ content }) => {
- const links = [...document.getElementsByClassName("internal-link")]
- links.forEach(li => {
- console.log(li.dataset)
- const linkDest = content[li.dataset.src.replace(basePath, "")]
+ fetchData.then(({ content }) => {
+ const links = [...document.getElementsByClassName("internal-link")]
+ links
+ .filter((li) => li.dataset.src)
+ .forEach((li) => {
+ const linkDest = content[li.dataset.src.replace(/\/$/g, "").replace(basePath, "")]
if (linkDest) {
const popoverElement = `<div class="popover">
<h3>${linkDest.title}</h3>
@@ -29,6 +29,5 @@
})
}
})
- })
})
}
--
Gitblit v1.10.0