Fix code blocks not changing to plots and others (#2497)

For some unknown reason, all the `document.onreadystatechange = () => {`
checks stopped working. Thankfully, replacing them with
`document.addEventListener("readystatechange", () => {` fixed the
issues.

---------

Signed-off-by: George Araujo <george.gcac@gmail.com>
This commit is contained in:
George 2024-06-11 14:06:38 -03:00 committed by GitHub
parent b861b015b0
commit 1a7fddecf8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 33 additions and 33 deletions

View File

@ -1,6 +1,6 @@
{% if site.back_to_top %}
<script src="{{ '/assets/js/vanilla-back-to-top.min.js' | relative_url | bust_file_cache }}"></script>
<script>
{% if site.back_to_top %}
addBackToTop();
{% endif %}
</script>
{% endif %}

View File

@ -6,11 +6,11 @@
crossorigin="anonymous"
></script>
<script>
let theme = determineComputedTheme();
let diff2HtmlTheme = determineComputedTheme();
/* Create diff2html as another node and hide the code block, appending the diff2html node after it
this is done to enable retrieving the code again when changing theme between light/dark */
document.onreadystatechange = () => {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-diff2html').forEach((elem) => {
const textData = elem.textContent;
@ -20,11 +20,11 @@
let diffElement = document.createElement('div');
diffElement.classList.add('diff2html');
backup.after(diffElement);
const configuration = { colorScheme: theme, drawFileList: true, highlight: true, matching: 'lines' };
const configuration = { colorScheme: diff2HtmlTheme, drawFileList: true, highlight: true, matching: 'lines' };
const diff2htmlUi = new Diff2HtmlUI(diffElement, textData, configuration);
diff2htmlUi.draw();
});
}
};
});
</script>
{% endif %}

View File

@ -12,11 +12,11 @@
></script>
{% endif %}
<script>
let theme = determineComputedTheme();
let echartsTheme = determineComputedTheme();
/* Create echarts chart as another node and hide the code block, appending the echarts node after it
this is done to enable retrieving the code again when changing theme between light/dark */
document.onreadystatechange = () => {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-echarts').forEach((elem) => {
const jsonData = elem.textContent;
@ -28,7 +28,7 @@
backup.after(chartElement);
/* create echarts */
if (theme === 'dark') {
if (echartsTheme === 'dark') {
var chart = echarts.init(chartElement, 'dark-fresh-cut');
} else {
var chart = echarts.init(chartElement);
@ -40,6 +40,6 @@
});
});
}
};
});
</script>
{% endif %}

View File

@ -6,7 +6,7 @@
></script>
<script>
/* Create leaflet map as another node and hide the code block, appending the leaflet node after it */
document.onreadystatechange = () => {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-geojson').forEach((elem) => {
const jsonData = elem.textContent;
@ -26,6 +26,6 @@
map.fitBounds(geoJSON.getBounds());
});
}
};
});
</script>
{% endif %}

View File

@ -14,11 +14,11 @@
></script>
{% endif %}
<script>
let theme = determineComputedTheme();
let mermaidTheme = determineComputedTheme();
/* Create mermaid diagram as another node and hide the code block, appending the mermaid node after it
this is done to enable retrieving the code again when changing theme between light/dark */
document.onreadystatechange = () => {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-mermaid').forEach((elem) => {
const svgCode = elem.textContent;
@ -32,7 +32,7 @@
backup.after(mermaid);
});
mermaid.initialize({ theme: theme });
mermaid.initialize({ theme: mermaidTheme });
/* Zoomable mermaid diagrams */
if (typeof d3 !== 'undefined') {
@ -50,6 +50,6 @@
});
}
}
};
});
</script>
{% endif %}

View File

@ -30,7 +30,7 @@
crossorigin="anonymous"
></script>
<script>
document.onreadystatechange = () => {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-pseudocode').forEach((elem) => {
const texData = elem.textContent;
@ -47,6 +47,6 @@
pseudocode.renderElement(pseudoCodeElement);
});
}
};
});
</script>
{% endif %}

View File

@ -2,10 +2,10 @@
<script type="module" src="{{ '/assets/js/search/ninja-keys.min.js' | relative_url | bust_file_cache }}"></script>
<ninja-keys hideBreadcrumbs noAutoLoadMdIcons placeholder="Type to start searching"></ninja-keys>
<script>
let theme = determineComputedTheme();
let searchTheme = determineComputedTheme();
const ninjaKeys = document.querySelector('ninja-keys');
if (theme === 'dark') {
if (searchTheme === 'dark') {
ninjaKeys.classList.add('dark');
} else {
ninjaKeys.classList.remove('dark');

View File

@ -4,7 +4,7 @@
<script>
/* Create typogram as another node and hide the code block, appending the typogram node after it
this is done to enable retrieving the code again when changing theme between light/dark */
document.onreadystatechange = () => {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-typograms').forEach((elem) => {
const texData = elem.textContent;
@ -18,6 +18,6 @@
parent.removeChild(elem.parentElement);
});
}
};
});
</script>
{% endif %}

View File

@ -19,11 +19,11 @@
></script>
<script>
let pageTheme = determineComputedTheme();
let vegaTheme = determineComputedTheme();
/* Create vega lite chart as another node and hide the code block, appending the vega lite node after it
this is done to enable retrieving the code again when changing theme between light/dark */
document.onreadystatechange = () => {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-vega_lite').forEach((elem) => {
const jsonData = elem.textContent;
@ -35,13 +35,13 @@
backup.after(chartElement);
/* Embed the visualization in the container */
if (pageTheme === 'dark') {
if (vegaTheme === 'dark') {
vegaEmbed(chartElement, JSON.parse(jsonData), { theme: 'dark' });
} else {
vegaEmbed(chartElement, JSON.parse(jsonData));
}
});
}
};
});
</script>
{% endif %}

View File

@ -37,12 +37,12 @@ $(document).ready(function () {
cssLink.rel = "stylesheet";
cssLink.type = "text/css";
let theme = determineComputedTheme();
let jupyterTheme = determineComputedTheme();
$(".jupyter-notebook-iframe-container iframe").each(function () {
$(this).contents().find("head").append(cssLink);
if (theme == "dark") {
if (jupyterTheme == "dark") {
$(this).bind("load", function () {
$(this).contents().find("body").attr({
"data-jp-theme-light": "false",

View File

@ -1,5 +1,5 @@
// Check if the user is on a Mac and update the shortcut key for search accordingly
document.onreadystatechange = () => {
document.addEventListener("readystatechange", () => {
if (document.readyState === "interactive") {
let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
let shortcutKeyElement = document.querySelector("#search-toggle .nav-link");
@ -8,4 +8,4 @@ document.onreadystatechange = () => {
shortcutKeyElement.innerHTML = '&#x2318; k <i class="ti ti-search"></i>';
}
}
};
});