chore: move js to single file
This commit is contained in:
File diff suppressed because one or more lines are too long
+21
-3
@@ -40,6 +40,18 @@
|
||||
document.body.style.removeProperty('padding-right');
|
||||
}
|
||||
|
||||
function swapPageModals(doc) {
|
||||
document.querySelectorAll('[data-ajax-modal="true"]').forEach(el => el.remove());
|
||||
doc.querySelectorAll('body > .modal').forEach(old => {
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.innerHTML = old.outerHTML;
|
||||
const modal = wrapper.firstElementChild;
|
||||
if (!modal) return;
|
||||
modal.setAttribute('data-ajax-modal', 'true');
|
||||
document.body.appendChild(modal);
|
||||
});
|
||||
}
|
||||
|
||||
// ── Per-page inline <style> management ───────────────────────────────────
|
||||
const STYLE_ID = 'ajax-page-style';
|
||||
function setPageStyles(cssText) {
|
||||
@@ -100,7 +112,7 @@
|
||||
// Then re-expose every named function declaration to `window` so that
|
||||
// inline onclick="foo()" handlers continue to resolve them globally.
|
||||
const funcNames = [
|
||||
...code.matchAll(/^(?:async\s+)?function\s+(\w+)\s*\(/gm),
|
||||
...code.matchAll(/^\s*(?:async\s+)?function\s+(\w+)\s*\(/gm),
|
||||
].map(m => m[1]);
|
||||
|
||||
const expose = funcNames
|
||||
@@ -161,13 +173,19 @@
|
||||
// Cleanup outgoing page, then inject new content
|
||||
cleanupPage();
|
||||
mainInner.innerHTML = doc.querySelector('.main-inner')?.innerHTML ?? '';
|
||||
swapPageModals(doc);
|
||||
document.title = doc.title;
|
||||
|
||||
const filename = href.split('/').pop();
|
||||
setActiveNav(filename);
|
||||
|
||||
// Execute the new page's inline scripts in order
|
||||
runInlineScripts(doc);
|
||||
// Execute page scripts from the centralized app bundle when available.
|
||||
if (typeof window.__runPageScripts === 'function') {
|
||||
window.__runPageScripts(filename);
|
||||
} else {
|
||||
// Fallback for legacy pages that still carry inline scripts.
|
||||
runInlineScripts(doc);
|
||||
}
|
||||
|
||||
} catch {
|
||||
// Fallback to hard navigation on any error
|
||||
|
||||
Reference in New Issue
Block a user