MirrorUbu/public/js/sandpoints.js
2024-04-09 11:07:59 +02:00

1 line
3.1 KiB
JavaScript

(()=>{window.addEventListener("scroll",function(i){if(document.querySelector("body").clientWidth>767){let o=document.querySelector(".rightcolumn"),e=document.querySelector(".mantletitle")||document.querySelector(".crusttitle")||!1;if(!e)return;let n=document.querySelector(".mantlebar"),l=document.querySelector(".grid"),t=e.getBoundingClientRect();if(document.querySelector("body").clientHeight-(l.clientHeight+e.clientHeight+32)<window.innerHeight)return;t.top<20&&!l.classList.contains("moved")?(l.classList.add("moved"),n.style.display="inline",e.style.visibility="hidden"):t.top>21&&l.classList.contains("moved")&&(l.classList.remove("moved"),e.style.visibility="visible",n.style.display="none")}else{let o=document.querySelector(".rightcolumn"),e=document.querySelector(".mantletitle")||document.querySelector(".crusttitle")||!1;if(!e)return;let n=document.querySelector(".mantlebar"),l=document.querySelector(".grid"),t=e.getBoundingClientRect();t.top<20&&!l.classList.contains("moved")?(l.classList.add("moved"),n.style.display="inline",e.style.visibility="hidden"):t.top>21&&l.classList.contains("moved")&&(l.classList.remove("moved"),e.style.visibility="visible",n.style.display="none")}});function c(i){let o="../".repeat(relPathDepth-1);var e=document.createElement("script");e.onload=()=>{console.log("loading..."),console.log(repo)},e.src=`${o}js/repo/${i}.js`,document.body.appendChild(e),document.location.href=`${o}edit/index.html?edit=${i}`,ev}window.addEventListener("keyup",i=>{if(i.key=="e"&&location.protocol=="file:")c(sandpointsPageId);else if(i.key=="E"&&location.protocol=="file:"){let o=document.querySelector("#preview");o.style.display=="flex"?o.style.display="none":o.style.display="flex",console.log("preview: ",o)}});window.addEventListener("DOMContentLoaded",i=>{location.protocol=="file:"&&document.querySelectorAll(".svedit").forEach(t=>{t.style.display="inline"}),document.querySelectorAll(".triadlink").forEach(t=>{t.addEventListener("click",r=>{r.ctrlKey&&(r.preventDefault(),c(r.target.getAttribute("repoid")))})});let o=document.querySelector("#preview");(location.pathname.split("/").includes("_preview")||location.hash.startsWith("#/_edit"))&&(o.style.display="flex");let e=document.querySelector("#TableOfContents > ol:first-child > li:first-child");if(e){let t=document.createElement("span");t.appendChild(e.cloneNode(!0)),e.remove(),document.querySelector("#TableOfContents > ol:first-child").insertBefore(t,document.querySelector("#TableOfContents > ol:first-child").firstChild)}if(document.querySelector(".soundcite")){let t="../".repeat(relPathDepth-1);var n=document.createElement("script");n.src=`${t}js/popcorn.min.js`,document.body.appendChild(n);var l=document.createElement("script");l.src=`${t}js/soundcite.min.js`,document.body.appendChild(l)}document.querySelectorAll("#TableOfContents a, .anchorz, .footnote-backref, .footnote-ref").forEach(t=>{t.addEventListener("click",r=>{setTimeout(()=>{window.scrollBy({top:document.querySelector(".header").clientHeight*-1.25,behavior:"smooth"})},50)})})});toggleAllLinks=function(){document.querySelectorAll("details").forEach(i=>{i.open?i.removeAttribute("open"):i.setAttribute("open",!0)})};})();