quartz/js/popover.b09d478d74c2f86dcb7758afddc318bf.min.js
2022-05-05 05:03:52 +00:00

9 lines
1.2 KiB
JavaScript

function htmlToElement(e){const t=document.createElement("template");return e=e.trim(),t.innerHTML=e,t.content.firstChild}function initPopover(e,t){const n=e.replace(window.location.origin,"");fetchData.then(({content:e})=>{const s=[...document.getElementsByClassName("internal-link")];s.filter(e=>e.dataset.src||e.dataset.idx&&t).forEach(t=>{if(t.dataset.ctx){const n=e[t.dataset.src],o=`<div class="popover">
<h3>${n.title}</h3>
<p>${highlight(removeMarkdown(n.content),t.dataset.ctx)}...</p>
<p class="meta">${new Date(n.lastmodified).toLocaleDateString()}</p>
</div>`,s=htmlToElement(o);t.appendChild(s),t.addEventListener("mouseover",()=>{s.classList.add("visible")}),t.addEventListener("mouseout",()=>{s.classList.remove("visible")})}else{const s=e[t.dataset.src.replace(/\/$/g,"").replace(n,"")];if(s){const n=`<div class="popover">
<h3>${s.title}</h3>
<p>${removeMarkdown(s.content).split(" ",20).join(" ")}...</p>
<p class="meta">${new Date(s.lastmodified).toLocaleDateString()}</p>
</div>`,e=htmlToElement(n);t.appendChild(e),t.addEventListener("mouseover",()=>{e.classList.add("visible")}),t.addEventListener("mouseout",()=>{e.classList.remove("visible")})}}})})}