Redesign shell: topbar + sidebar navigation, ui.js, new test list markup
- base.html: new topbar/sidebar/main layout, accessible mobile menu, dismissible message banners, toast container, page_head block - ui.js: current-page nav highlight, mobile menu close, copy toast - index/testsummary: one card per section with column headers, labelled flags instead of coloured asterisks, empty state - pagebrowser: nav landmark + aria labels All Django logic, URLs, IDs and JS hooks are unchanged.
This commit is contained in:
1 parent
7bbcff231d
commit
cb3d99fa45
6 files changed
+390
-154
No files matched your search
@@ -0,0 +1,136 @@
|
||||
/* ==========================================================================
|
||||
OpenBench - small UI helpers (progressive enhancement only).
|
||||
Nothing here changes what the site does: it highlights the current page in
|
||||
the navigation, closes the mobile menu, shows a toast after copying text and
|
||||
lets message banners be dismissed.
|
||||
========================================================================== */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function ready(fn) {
|
||||
if (document.readyState !== 'loading')
|
||||
fn();
|
||||
else
|
||||
document.addEventListener('DOMContentLoaded', fn);
|
||||
}
|
||||
|
||||
function normalise(path) {
|
||||
path = path.replace(/\/+$/, '');
|
||||
return path === '' ? '/' : path;
|
||||
}
|
||||
|
||||
/* ---------- Navigation: mark the link for the current page ---------- */
|
||||
|
||||
function highlightNavigation() {
|
||||
|
||||
var here = normalise(window.location.pathname);
|
||||
|
||||
// The front page is served from both / and /index
|
||||
if (here === '/')
|
||||
here = '/index';
|
||||
|
||||
var best = null;
|
||||
var bestLength = -1;
|
||||
|
||||
document.querySelectorAll('#sidebar a[href^="/"]').forEach(function (link) {
|
||||
|
||||
var target = normalise(new URL(link.getAttribute('href'), window.location.origin).pathname);
|
||||
var matches = here === target || here.indexOf(target + '/') === 0;
|
||||
|
||||
if (matches && target.length > bestLength) {
|
||||
best = link;
|
||||
bestLength = target.length;
|
||||
}
|
||||
});
|
||||
|
||||
if (best) {
|
||||
best.classList.add('active');
|
||||
best.setAttribute('aria-current', 'page');
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Mobile navigation ---------- */
|
||||
|
||||
function setSidebar(open) {
|
||||
document.body.classList.toggle('sidebar-open', open);
|
||||
var toggle = document.getElementById('sidebar-toggle');
|
||||
if (toggle)
|
||||
toggle.setAttribute('aria-expanded', String(open));
|
||||
}
|
||||
|
||||
function initSidebar() {
|
||||
|
||||
var backdrop = document.getElementById('sidebar-backdrop');
|
||||
if (backdrop)
|
||||
backdrop.addEventListener('click', function () { setSidebar(false); });
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape')
|
||||
setSidebar(false);
|
||||
});
|
||||
|
||||
document.querySelectorAll('#sidebar a').forEach(function (link) {
|
||||
link.addEventListener('click', function () { setSidebar(false); });
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- Toast ---------- */
|
||||
|
||||
var toastTimer = null;
|
||||
|
||||
function toast(message) {
|
||||
|
||||
var element = document.getElementById('toast');
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
element.textContent = message;
|
||||
element.classList.add('show');
|
||||
|
||||
window.clearTimeout(toastTimer);
|
||||
toastTimer = window.setTimeout(function () {
|
||||
element.classList.remove('show');
|
||||
}, 1800);
|
||||
}
|
||||
|
||||
// Give copy_text() (see copy_text.js) some visible feedback
|
||||
function wrapCopyText() {
|
||||
|
||||
if (typeof window.copy_text !== 'function' || window.copy_text.wrapped)
|
||||
return;
|
||||
|
||||
var original = window.copy_text;
|
||||
|
||||
window.copy_text = function () {
|
||||
var result = original.apply(this, arguments);
|
||||
toast('Copied to clipboard');
|
||||
return result;
|
||||
};
|
||||
|
||||
window.copy_text.wrapped = true;
|
||||
}
|
||||
|
||||
/* ---------- Dismissible banners ---------- */
|
||||
|
||||
function initBanners() {
|
||||
document.addEventListener('click', function (event) {
|
||||
|
||||
var button = event.target.closest('.banner-close');
|
||||
if (!button)
|
||||
return;
|
||||
|
||||
var banner = button.closest('.banner');
|
||||
if (banner)
|
||||
banner.remove();
|
||||
});
|
||||
}
|
||||
|
||||
ready(function () {
|
||||
highlightNavigation();
|
||||
initSidebar();
|
||||
initBanners();
|
||||
wrapCopyText();
|
||||
});
|
||||
|
||||
})();
|
||||
Reference in new issue
Block a user