CSS: - Remove duplicate li::before block in app-search.css - Fix typo: search-reuslt → search-result in app-search.css - Remove commented-out CSS rules in app-flash.css - Add descriptive header comment to all 27 CSS component files JS: - Complete WAI-ARIA Tabs pattern: generate IDs, add aria-controls on tab buttons and aria-labelledby on tab panels (app-tabs.js) - Add JSDoc header comments to ~33 JS files (core + components) - Add explanatory block comment to app-boot.js (why classic IIFE) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
/**
|
|
* Browser history integration — handles back/forward navigation state.
|
|
*/
|
|
const updateHistoryButtons = () => {
|
|
const back = document.querySelector('#global-back');
|
|
const forward = document.querySelector('#global-forward');
|
|
if (!back && !forward) {return;}
|
|
|
|
const hasHistory = window.history.length > 1;
|
|
const setDisabledState = (link, disabled) => {
|
|
link.setAttribute('aria-disabled', disabled ? 'true' : 'false');
|
|
link.classList.toggle('is-disabled', disabled);
|
|
if (disabled) {
|
|
link.setAttribute('tabindex', '-1');
|
|
} else {
|
|
link.removeAttribute('tabindex');
|
|
}
|
|
};
|
|
|
|
if (back) {
|
|
setDisabledState(back, !hasHistory);
|
|
}
|
|
if (forward) {
|
|
setDisabledState(forward, !hasHistory);
|
|
}
|
|
};
|
|
|
|
const initHistoryButtons = () => {
|
|
const back = document.querySelector('#global-back');
|
|
const forward = document.querySelector('#global-forward');
|
|
|
|
const isEditableTarget = (target) => {
|
|
if (!target) {return false;}
|
|
if (target.isContentEditable) {return true;}
|
|
const tag = target.tagName;
|
|
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
|
|
};
|
|
|
|
document.addEventListener('keydown', (event) => {
|
|
if (!event.altKey || event.metaKey || event.ctrlKey) {return;}
|
|
if (isEditableTarget(event.target)) {return;}
|
|
if (event.key === 'ArrowLeft') {
|
|
if (window.history.length > 1) {
|
|
event.preventDefault();
|
|
window.history.back();
|
|
}
|
|
} else if (event.key === 'ArrowRight') {
|
|
if (window.history.length > 1) {
|
|
event.preventDefault();
|
|
window.history.forward();
|
|
}
|
|
}
|
|
});
|
|
|
|
if (back) {
|
|
back.addEventListener('click', (event) => {
|
|
event.preventDefault();
|
|
if (window.history.length > 1) {
|
|
window.history.back();
|
|
}
|
|
});
|
|
}
|
|
|
|
if (forward) {
|
|
forward.addEventListener('click', (event) => {
|
|
event.preventDefault();
|
|
if (window.history.length > 1) {
|
|
window.history.forward();
|
|
}
|
|
});
|
|
}
|
|
|
|
updateHistoryButtons();
|
|
window.addEventListener('popstate', updateHistoryButtons);
|
|
};
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initHistoryButtons);
|
|
} else {
|
|
initHistoryButtons();
|
|
}
|