Skip to content

Spoilers should be expanded in print CSS layout #2041

Answered by ComFreek
ComFreek asked this question in Ideas
Discussion options

You must be logged in to vote

I've come up with the JS script below that will expand spoilers for printing and revert them after printing.

Usage: Save the JS below as assets/js/print-spoiler-contents.js; create the js directory if non-existing. In config/_default/params.toml, locate the plugins_js setting and add print-spoiler-contents to it; e.g. to get plugins_js = ["print-spoiler-contents"].

let expandedSpoilers = [];

window.addEventListener("beforeprint", () => {
    expandedSpoilers = [];
    for (const spoiler of document.querySelectorAll(".spoiler a[aria-expanded=false]")) {
        expandedSpoilers.push(spoiler);
        spoiler.click();
    };
});

window.addEventListener("afterprint", () => {
    for (const s…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@ComFreek
Comment options

@ComFreek
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ComFreek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants