-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add function to open all accordions for printing and close …
…all accordions after printing (except those previously opened)
- Loading branch information
1 parent
e9c1ae7
commit 00e560d
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export default function accordion () { | ||
const BROWSER_WINDOW = window | ||
|
||
const closeAllAccordions = () => { | ||
const OPEN_ACCORDION_ELS = document.querySelectorAll('details[open]') | ||
|
||
OPEN_ACCORDION_ELS.forEach((openAccordionEl) => { | ||
openAccordionEl.removeAttribute('open') | ||
}) | ||
} | ||
|
||
const openAllAccordions = () => { | ||
const OPEN_ACCORDION_ELS = document.querySelectorAll('details') | ||
|
||
OPEN_ACCORDION_ELS.forEach((openAccordionEl) => { | ||
openAccordionEl.setAttribute('open', '') | ||
}) | ||
} | ||
|
||
/** | ||
* Expand all accordions for printing, restore previously opened accordions | ||
* after printing | ||
* | ||
*/ | ||
let openAccordionEls | ||
|
||
BROWSER_WINDOW.addEventListener('beforeprint', () => { | ||
openAccordionEls = document.querySelectorAll('details[open]') | ||
|
||
openAllAccordions() | ||
}) | ||
|
||
BROWSER_WINDOW.addEventListener('afterprint', () => { | ||
closeAllAccordions() | ||
|
||
openAccordionEls.forEach((openAccordionEl) => { | ||
openAccordionEl.setAttribute('open', '') | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters