mirror of
https://github.com/github/awesome-copilot.git
synced 2026-06-15 04:15:03 +00:00
76ac13a9b8
* Removing search from the home pageThis was a little confusing because there are two searches, but the overall site search is a lot more powerful * Prefilter website search by resource page Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * small error handling and formatting * Simplify website listing controls Remove per-page text search, trim page-specific controls, and move remaining sort/filter controls into compact flyouts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
declare global {
|
|
interface Window {
|
|
__awesomeCopilotListingFlyoutsInitialized?: boolean;
|
|
}
|
|
}
|
|
|
|
const FLYOUT_SELECTOR = '.listing-controls';
|
|
|
|
function closeFlyouts(except?: HTMLDetailsElement): void {
|
|
document.querySelectorAll<HTMLDetailsElement>(FLYOUT_SELECTOR).forEach((flyout) => {
|
|
if (flyout !== except) {
|
|
flyout.open = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
export function initListingFlyouts(): void {
|
|
if (window.__awesomeCopilotListingFlyoutsInitialized) return;
|
|
|
|
document.addEventListener(
|
|
'toggle',
|
|
(event) => {
|
|
const flyout = event.target;
|
|
if (!(flyout instanceof HTMLDetailsElement) || !flyout.matches(FLYOUT_SELECTOR) || !flyout.open) {
|
|
return;
|
|
}
|
|
|
|
closeFlyouts(flyout);
|
|
},
|
|
true
|
|
);
|
|
|
|
document.addEventListener('click', (event) => {
|
|
const target = event.target;
|
|
if (target instanceof Element && target.closest(FLYOUT_SELECTOR)) {
|
|
return;
|
|
}
|
|
|
|
closeFlyouts();
|
|
});
|
|
|
|
document.addEventListener('keydown', (event) => {
|
|
if (event.key !== 'Escape') return;
|
|
|
|
const activeFlyout = document.activeElement instanceof Element
|
|
? (document.activeElement.closest(FLYOUT_SELECTOR) as HTMLDetailsElement | null)
|
|
: null;
|
|
|
|
closeFlyouts();
|
|
|
|
const summary = activeFlyout?.querySelector('summary');
|
|
if (summary instanceof HTMLElement) {
|
|
summary.focus();
|
|
}
|
|
});
|
|
|
|
window.__awesomeCopilotListingFlyoutsInitialized = true;
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initListingFlyouts, { once: true });
|
|
} else {
|
|
initListingFlyouts();
|
|
}
|