amethyst/quartz/js/popover.f03552ccb84d99ca615d1cfb9abde59e.min.js

9 lines
1.5 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=>{let s;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)}else{const o=e[t.dataset.src.replace(/\/$/g,"").replace(n,"")];if(o){let n=t.href.split("#"),e=removeMarkdown(o.content);if(n.length>1){let t=decodeURIComponent(n[1]).replace(/-/g," "),s=e.toLowerCase().indexOf("<b>"+t+"</b>");e=e.substring(s,e.length)}const i=`<div class="popover">
<h3>${o.title}</h3>
<p>${e.split(" ",20).join(" ")}...</p>
<p class="meta">${new Date(o.lastmodified).toLocaleDateString()}</p>
</div>`;s=htmlToElement(i)}}s&&(t.appendChild(s),LATEX_ENABLED&&renderMathInElement(s,{delimiters:[{left:"$$",right:"$$",display:!1},{left:"$",right:"$",display:!1}],throwOnError:!1}),t.addEventListener("mouseover",()=>{window.FloatingUIDOM.computePosition(t,s,{middleware:[window.FloatingUIDOM.offset(10),window.FloatingUIDOM.inline(),window.FloatingUIDOM.shift()]}).then(({x:e,y:t})=>{Object.assign(s.style,{left:`${e}px`,top:`${t}px`})}),s.classList.add("visible")}),t.addEventListener("mouseout",()=>{s.classList.remove("visible")}))})})}