mirror of
https://github.com/logos-co/roadmap.git
synced 2025-02-22 12:48:29 +00:00
9 lines
1.4 KiB
JavaScript
9 lines
1.4 KiB
JavaScript
function htmlToElement(e){const t=document.createElement("template");return e=e.trim(),t.innerHTML=e,t.content.firstChild}function initPopover(e,t,n){const s=e.replace(window.location.origin,"");fetchData.then(({content:e})=>{const o=[...document.getElementsByClassName("internal-link")];o.filter(e=>e.dataset.src||e.dataset.idx&&t).forEach(t=>{var o;if(t.dataset.ctx){const n=e[t.dataset.src],s=`<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>`;o=htmlToElement(s)}else{const n=e[t.dataset.src.replace(/\/$/g,"").replace(s,"")];if(n){const e=`<div class="popover">
|
|
<h3>${n.title}</h3>
|
|
<p>${removeMarkdown(n.content).split(" ",20).join(" ")}...</p>
|
|
<p class="meta">${new Date(n.lastmodified).toLocaleDateString()}</p>
|
|
</div>`;o=htmlToElement(e)}}o&&(t.appendChild(o),n&&renderMathInElement(o,{delimiters:[{left:"$$",right:"$$",display:!1},{left:"$",right:"$",display:!1},{left:"\\(",right:"\\)",display:!1},{left:"\\[",right:"\\]",display:!1}],throwOnError:!1}),t.addEventListener("mouseover",()=>{window.FloatingUIDOM.computePosition(t,o,{middleware:[window.FloatingUIDOM.offset(10),window.FloatingUIDOM.inline(),window.FloatingUIDOM.shift()]}).then(({x:e,y:t})=>{Object.assign(o.style,{left:`${e}px`,top:`${t}px`})}),o.classList.add("visible")}),t.addEventListener("mouseout",()=>{o.classList.remove("visible")}))})})} |