Skip to content

Commit

Permalink
feat: open accordions when printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Arukuen committed May 26, 2024
1 parent c51a945 commit e16f5a2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/block/accordion/frontend-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,24 @@ class StackableAccordion {
}

window.stackableAccordion = new StackableAccordion()

// Open closed accordions when printing
// and close them again after printing
window.matchMedia( 'print' ).addEventListener( 'change', event => {
if ( event.matches ) {
const els = document.querySelectorAll( 'details.stk-block-accordion:not([open])' )
for ( const el of els ) {
el.setAttribute( 'open', '' )
// Mark the elements so they can be closed again after printing
el.dataset.wasclosed = ''
}
} else {
const els = document.body.querySelectorAll( 'details.stk-block-accordion[data-wasclosed]' )
for ( const el of els ) {
el.removeAttribute( 'open' )
delete el.dataset.wasclosed
}
}
} )

domReady( window.stackableAccordion.init )

0 comments on commit e16f5a2

Please sign in to comment.