mirror of
https://github.com/HERDAC/Cours-programmation.git
synced 2024-11-24 18:43:28 +00:00
5 lines
796 B
JavaScript
5 lines
796 B
JavaScript
function htmlToElement(e){const t=document.createElement("template");return e=e.trim(),t.innerHTML=e,t.content.firstChild}function initPopover(e){const t=e.replace(window.location.origin,"");document.addEventListener("DOMContentLoaded",()=>{fetchData.then(({content:e})=>{const n=[...document.getElementsByClassName("internal-link")];n.filter(e=>e.dataset.src).forEach(n=>{const s=e[n.dataset.src.replace(t,"")];if(s){const t=`<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(t);n.appendChild(e),n.addEventListener("mouseover",()=>{e.classList.add("visible")}),n.addEventListener("mouseout",()=>{e.classList.remove("visible")})}})})})} |