Files
dekun e5a586f903 Restructure into modules/ with single-process CTP and config/ layout.
Move business code under modules/, env template to config/, PM2 single qihuo process, and _legacy shims for old imports.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 14:42:16 +08:00

87 lines
2.7 KiB
JavaScript

/* Copyright (c) 2025-2026 马建军. All rights reserved.
* 专有软件 — 未经授权禁止复制、传播、转售。
* 详见 LICENSE.zh-CN.txt
*/
(function () {
var toggle = document.getElementById('nav-toggle');
var nav = document.getElementById('site-nav');
var backdrop = document.getElementById('nav-backdrop');
if (!toggle || !nav) return;
function openNav() {
nav.classList.add('open');
if (backdrop) {
backdrop.hidden = false;
backdrop.classList.add('show');
}
toggle.setAttribute('aria-expanded', 'true');
document.body.style.overflow = 'hidden';
}
function closeNav() {
nav.classList.remove('open');
if (backdrop) {
backdrop.classList.remove('show');
backdrop.hidden = true;
}
toggle.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
}
function isMobileNav() {
if (window.qihuoLayout && window.qihuoLayout.isPhone()) return true;
return document.documentElement.dataset.mobile === '1'
|| window.matchMedia('(max-width: 767px)').matches;
}
toggle.addEventListener('click', function () {
if (nav.classList.contains('open')) closeNav();
else openNav();
});
if (backdrop) {
backdrop.addEventListener('click', closeNav);
}
function prefetchNav(href) {
if (!href || href.indexOf(window.location.origin) !== 0) return;
if (href === window.location.href) return;
var links = document.head.querySelectorAll('link[rel="prefetch"]');
for (var i = 0; i < links.length; i++) {
if (links[i].href === href) return;
}
var link = document.createElement('link');
link.rel = 'prefetch';
link.href = href;
document.head.appendChild(link);
}
nav.querySelectorAll('a[href]').forEach(function (link) {
link.addEventListener('click', function () {
if (isMobileNav()) closeNav();
});
link.addEventListener('mouseenter', function () {
prefetchNav(link.href);
});
link.addEventListener('touchstart', function () {
prefetchNav(link.href);
}, { passive: true });
});
window.addEventListener('resize', function () {
if (!isMobileNav()) closeNav();
});
if (window.qihuoLayout) {
window.addEventListener('orientationchange', function () {
setTimeout(function () {
if (!isMobileNav()) closeNav();
}, 150);
});
}
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') closeNav();
});
})();