Update app.js
This commit is contained in:
parent
e85956237c
commit
f5911b12a4
1 changed files with 13 additions and 5 deletions
|
|
@ -15,6 +15,7 @@ const els = {
|
||||||
|
|
||||||
let indexData = null;
|
let indexData = null;
|
||||||
let sidebarOpen = false;
|
let sidebarOpen = false;
|
||||||
|
let currentIframe = null;
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -78,10 +79,13 @@ function wireUI() {
|
||||||
[els.tagSelect, els.sortSelect, els.searchMode].forEach(el => el.addEventListener("change", renderList));
|
[els.tagSelect, els.sortSelect, els.searchMode].forEach(el => el.addEventListener("change", renderList));
|
||||||
els.searchBox.addEventListener("input", renderList);
|
els.searchBox.addEventListener("input", renderList);
|
||||||
|
|
||||||
els.content.addEventListener("click", () => {
|
// Click outside to close sidebar (works on iframe too)
|
||||||
|
els.content.addEventListener("click", (e) => {
|
||||||
if (window.innerWidth < 1024 && document.body.classList.contains("sidebar-open")) {
|
if (window.innerWidth < 1024 && document.body.classList.contains("sidebar-open")) {
|
||||||
document.body.classList.remove("sidebar-open");
|
if (!e.target.closest("#sidebar")) {
|
||||||
sidebarOpen = false;
|
document.body.classList.remove("sidebar-open");
|
||||||
|
sidebarOpen = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -160,17 +164,21 @@ function renderIframe(rel) {
|
||||||
iframe.setAttribute("sandbox", "allow-same-origin allow-scripts allow-forms");
|
iframe.setAttribute("sandbox", "allow-same-origin allow-scripts allow-forms");
|
||||||
els.viewer.appendChild(iframe);
|
els.viewer.appendChild(iframe);
|
||||||
|
|
||||||
|
currentIframe = iframe;
|
||||||
|
|
||||||
iframe.onload = () => {
|
iframe.onload = () => {
|
||||||
if (rel.endsWith('.pdf')) return;
|
|
||||||
try {
|
try {
|
||||||
const doc = iframe.contentDocument;
|
const doc = iframe.contentDocument;
|
||||||
const style = doc.createElement("style");
|
const style = doc.createElement("style");
|
||||||
style.textContent = `
|
style.textContent = `
|
||||||
html,body{background:#0b0b0b;color:#e6e3d7;font-family:Inter,sans-serif;margin:0;padding:2rem;}
|
html,body{background:#0b0b0b;color:#e6e3d7;font-family:Inter,sans-serif;margin:0;padding:2rem;}
|
||||||
*{max-width:720px;margin:auto;}
|
*{max-width:720px;margin:auto;}
|
||||||
|
img, video, iframe {max-width:100%;height:auto;}
|
||||||
`;
|
`;
|
||||||
doc.head.appendChild(style);
|
doc.head.appendChild(style);
|
||||||
} catch {}
|
} catch (e) {
|
||||||
|
// Cross-origin: ignore
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue