Skip to content

Commit 542fa52

Browse files
author
DavidQ
committed
Add fullscreen when collapse header, exit by clicking again
1 parent 426e953 commit 542fa52

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/engine/theme/mount-shared-header.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,38 @@ async function mountSampleDetailEnhancementIfNeeded() {
2222
}
2323

2424
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
25+
const headerIntroAccordion = document.querySelector('.is-collapsible');
26+
const headerIntroSummary = headerIntroAccordion?.querySelector('.is-collapsible__summary');
27+
const isHeaderIntroAccordion = headerIntroAccordion instanceof HTMLDetailsElement
28+
&& headerIntroSummary instanceof HTMLElement
29+
&& headerIntroSummary.textContent?.trim().toLowerCase() === 'header and intro';
30+
31+
if (isHeaderIntroAccordion) {
32+
headerIntroAccordion.addEventListener('toggle', async () => {
33+
if (!document.fullscreenEnabled) {
34+
return;
35+
}
36+
37+
if (headerIntroAccordion.open) {
38+
if (document.fullscreenElement) {
39+
try {
40+
await document.exitFullscreen();
41+
} catch {
42+
// Ignore fullscreen exit failures because accordion state remains usable.
43+
}
44+
}
45+
return;
46+
}
47+
48+
if (!document.fullscreenElement && typeof document.documentElement?.requestFullscreen === 'function') {
49+
try {
50+
await document.documentElement.requestFullscreen();
51+
} catch {
52+
// Ignore fullscreen request failures because accordion state remains usable.
53+
}
54+
}
55+
});
56+
}
57+
2558
void mountSampleDetailEnhancementIfNeeded();
2659
}

0 commit comments

Comments
 (0)