Skip to content

Commit b21884c

Browse files
pchampingkellogg
authored andcommitted
replaced CSS hack by JS solution
I tested it with Firefox 68.0.1 and Chromium 76.0.3809.87 on Linux.
1 parent caa815e commit b21884c

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

index.html

+44-10
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,51 @@
273273
padding-left: 2em;
274274
font-style: italic;
275275
}
276+
</style>
277+
<script>
278+
(function() {
279+
function beforePrint() {
280+
console.debug("opening details before printing");
281+
var algoDetails = document.querySelectorAll('.algorithm details');
282+
var c = 0;
283+
for (var dt of algoDetails) {
284+
285+
if (!dt.open) {
286+
dt.setAttribute("data-was-closed", "");
287+
dt.open = true;
288+
c += 1;
289+
}
290+
}
291+
console.debug(c, "details opended before printing");
292+
}
276293

277-
/* required if we chose to put OLs *outside* the details,
278-
to force them visible when printing */
279-
@media screen {
280-
.algorithm details:not([open]) + ol {
281-
display: none;
294+
function afterPrint() {
295+
console.debug("closing details after printing");
296+
var algoDetails = document.querySelectorAll('.algorithm details');
297+
var c = 0;
298+
for (var dt of algoDetails) {
299+
if (dt.hasAttribute("data-was-closed")) {
300+
dt.removeAttribute("data-was-closed");
301+
dt.open = false;
302+
c += 1;
303+
}
304+
}
305+
console.debug(c, "details closed after printing");
282306
}
283-
}
284307

285-
</style>
308+
// using matchMedia
309+
window.matchMedia('print').addListener(function (mql) {
310+
if (mql.matches) {
311+
beforePrint();
312+
} else {
313+
afterPrint();
314+
}
315+
});
316+
// using events
317+
window.addEventListener('beforeprint', beforePrint);
318+
window.addEventListener('afterprint', afterPrint);
319+
})();
320+
</script>
286321
</head>
287322

288323
<body>
@@ -1091,8 +1126,7 @@ <h3>Algorithm</h3>
10911126
For each item <var>context</var> in <var>local context</var>:
10921127
<ol>
10931128
<li>If <var>context</var> is <code>null</code>:
1094-
<details><summary>clear context (unless protected)</summary></details>
1095-
<ol>
1129+
<details><summary>clear context (unless protected)</summary><ol>
10961130
<li class="changed">If <var>override protected</var> is <code>false</code> and <var>active context</var>
10971131
contains any <a>protected</a> <a>term definitions</a>,
10981132
an <a data-link-for="JsonLdErrorCode">invalid context nullification</a>
@@ -1105,7 +1139,7 @@ <h3>Algorithm</h3>
11051139
<span class="note">In [[[JSON-LD]]], the <a>base IRI</a> was given
11061140
a default value here; this is now described conditionally
11071141
in <a href="#the-application-programming-interface" class="sectionRef"></a>.</span></li>
1108-
</ol>
1142+
</ol></details>
11091143
</li>
11101144
<li>If <var>context</var> is a <a>string</a>:
11111145
<details><summary>dereference and process</summary><ol>

0 commit comments

Comments
 (0)