Update app.js
This commit is contained in:
parent
a5a18885d4
commit
c8ffd438cb
1 changed files with 11 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
/* ============================================================
|
/* ============================================================
|
||||||
The Fold Within — Framework v2.5 Stable Render Build
|
The Fold Within — Framework v2.6 Stable Layout Build
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
|
||||||
let INDEX, CURRENT_PATH = null, PATH_TO_EL = new Map();
|
let INDEX, CURRENT_PATH = null, PATH_TO_EL = new Map();
|
||||||
|
|
@ -22,7 +22,7 @@ const overlay = document.querySelector(".overlay");
|
||||||
navToggle.addEventListener("click", () => sidebar.classList.toggle("open"));
|
navToggle.addEventListener("click", () => sidebar.classList.toggle("open"));
|
||||||
overlay.addEventListener("click", () => sidebar.classList.remove("open"));
|
overlay.addEventListener("click", () => sidebar.classList.remove("open"));
|
||||||
|
|
||||||
/* Load index and init */
|
/* Load index and initialize */
|
||||||
async function loadIndex() {
|
async function loadIndex() {
|
||||||
const res = await fetch("/index.json", { cache: "no-store" });
|
const res = await fetch("/index.json", { cache: "no-store" });
|
||||||
INDEX = await res.json();
|
INDEX = await res.json();
|
||||||
|
|
@ -50,7 +50,7 @@ function populateFilters() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tree */
|
/* Tree building */
|
||||||
function rebuildTree() {
|
function rebuildTree() {
|
||||||
treeEl.innerHTML = "";
|
treeEl.innerHTML = "";
|
||||||
PATH_TO_EL.clear();
|
PATH_TO_EL.clear();
|
||||||
|
|
@ -109,7 +109,7 @@ function renderNode(n) {
|
||||||
function iconForExt(ext){return ext===".md"?"📝":"🧩";}
|
function iconForExt(ext){return ext===".md"?"📝":"🧩";}
|
||||||
function fmtDate(ms){return new Date(ms).toISOString().slice(0,10);}
|
function fmtDate(ms){return new Date(ms).toISOString().slice(0,10);}
|
||||||
|
|
||||||
/* Open file */
|
/* File open */
|
||||||
async function openPath(path){
|
async function openPath(path){
|
||||||
if(path===CURRENT_PATH) return;
|
if(path===CURRENT_PATH) return;
|
||||||
CURRENT_PATH=path;
|
CURRENT_PATH=path;
|
||||||
|
|
@ -128,7 +128,7 @@ async function openPath(path){
|
||||||
if(window.innerWidth<900) sidebar.classList.remove("open");
|
if(window.innerWidth<900) sidebar.classList.remove("open");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Markdown render */
|
/* Markdown renderer */
|
||||||
async function renderMarkdown(path){
|
async function renderMarkdown(path){
|
||||||
mdWarn.style.display = "none";
|
mdWarn.style.display = "none";
|
||||||
mdView.innerHTML="<p class='loading-note'>Loading…</p>";
|
mdView.innerHTML="<p class='loading-note'>Loading…</p>";
|
||||||
|
|
@ -147,25 +147,22 @@ async function renderMarkdown(path){
|
||||||
mdView.classList.remove("fade-in");
|
mdView.classList.remove("fade-in");
|
||||||
mdView.innerHTML=safe;
|
mdView.innerHTML=safe;
|
||||||
mdView.scrollTop=0;
|
mdView.scrollTop=0;
|
||||||
mdView.offsetHeight; // force reflow
|
mdView.offsetHeight;
|
||||||
mdView.classList.add("fade-in");
|
mdView.classList.add("fade-in");
|
||||||
if(usedFallback) mdWarn.style.display="block";
|
if(usedFallback) mdWarn.style.display="block";
|
||||||
|
|
||||||
// layout stabilization
|
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
const content=document.querySelector(".content");
|
const content=document.querySelector(".content");
|
||||||
if(content){
|
if(content){
|
||||||
const vh=window.innerHeight;
|
const vh=window.innerHeight;
|
||||||
content.style.minHeight=`${vh-48}px`;
|
content.style.minHeight=`${vh-48}px`;
|
||||||
content.style.paddingBottom="40px";
|
|
||||||
}
|
}
|
||||||
mdView.scrollIntoView({behavior:"instant",block:"start"});
|
mdView.scrollIntoView({behavior:"instant",block:"start"});
|
||||||
},80);
|
},80);
|
||||||
|
|
||||||
}catch(e){ mdView.innerHTML=`<p style='color:red;'>${e.message}</p>`; }
|
}catch(e){ mdView.innerHTML=`<p style='color:red;'>${e.message}</p>`; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HTML render */
|
/* HTML renderer */
|
||||||
function renderHTML(path){
|
function renderHTML(path){
|
||||||
htmlView.src="/"+path;
|
htmlView.src="/"+path;
|
||||||
htmlView.style.display="block";
|
htmlView.style.display="block";
|
||||||
|
|
@ -184,7 +181,7 @@ function renderHTML(path){
|
||||||
},120);
|
},120);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Active & Pager */
|
/* Active + pager */
|
||||||
function setActive(path){
|
function setActive(path){
|
||||||
document.querySelectorAll(".file.active").forEach(el=>el.classList.remove("active"));
|
document.querySelectorAll(".file.active").forEach(el=>el.classList.remove("active"));
|
||||||
const el=PATH_TO_EL.get(path);
|
const el=PATH_TO_EL.get(path);
|
||||||
|
|
@ -214,7 +211,7 @@ function updatePager(){
|
||||||
nextBtn.onclick=()=>i<list.length-1&&openPath(list[i+1].path);
|
nextBtn.onclick=()=>i<list.length-1&&openPath(list[i+1].path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search/filter */
|
/* Search + filter */
|
||||||
let searchTimer;
|
let searchTimer;
|
||||||
searchBox.addEventListener("input",()=>{
|
searchBox.addEventListener("input",()=>{
|
||||||
clearTimeout(searchTimer);
|
clearTimeout(searchTimer);
|
||||||
|
|
@ -223,7 +220,7 @@ searchBox.addEventListener("input",()=>{
|
||||||
sortSel.addEventListener("change",rebuildTree);
|
sortSel.addEventListener("change",rebuildTree);
|
||||||
filterSel.addEventListener("change",rebuildTree);
|
filterSel.addEventListener("change",rebuildTree);
|
||||||
|
|
||||||
/* Internal links */
|
/* Internal link interception */
|
||||||
document.body.addEventListener("click",e=>{
|
document.body.addEventListener("click",e=>{
|
||||||
const a=e.target.closest("a[href]");
|
const a=e.target.closest("a[href]");
|
||||||
if(!a) return;
|
if(!a) return;
|
||||||
|
|
@ -234,7 +231,7 @@ document.body.addEventListener("click",e=>{
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Resize listener */
|
/* Resize */
|
||||||
window.addEventListener("resize",()=>{
|
window.addEventListener("resize",()=>{
|
||||||
const vh=window.innerHeight;
|
const vh=window.innerHeight;
|
||||||
const c=document.querySelector(".content");
|
const c=document.querySelector(".content");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue