c5262a0a54
Mobile gets compact trade/records UI with detail modals; static assets are cache-busted and settings cards fold correctly on tablet grid layout. Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
2.7 KiB
JavaScript
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();
|
|
});
|
|
})();
|