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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,11 +19,11 @@
></script> ></script>
<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 /* 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 */ this is done to enable retrieving the code again when changing theme between light/dark */
document.onreadystatechange = () => { document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') { if (document.readyState === 'complete') {
document.querySelectorAll('pre>code.language-vega_lite').forEach((elem) => { document.querySelectorAll('pre>code.language-vega_lite').forEach((elem) => {
const jsonData = elem.textContent; const jsonData = elem.textContent;
@ -35,13 +35,13 @@
backup.after(chartElement); backup.after(chartElement);
/* Embed the visualization in the container */ /* Embed the visualization in the container */
if (pageTheme === 'dark') { if (vegaTheme === 'dark') {
vegaEmbed(chartElement, JSON.parse(jsonData), { theme: 'dark' }); vegaEmbed(chartElement, JSON.parse(jsonData), { theme: 'dark' });
} else { } else {
vegaEmbed(chartElement, JSON.parse(jsonData)); vegaEmbed(chartElement, JSON.parse(jsonData));
} }
}); });
} }
}; });
</script> </script>
{% endif %} {% endif %}

View File

@ -37,12 +37,12 @@ $(document).ready(function () {
cssLink.rel = "stylesheet"; cssLink.rel = "stylesheet";
cssLink.type = "text/css"; cssLink.type = "text/css";
let theme = determineComputedTheme(); let jupyterTheme = determineComputedTheme();
$(".jupyter-notebook-iframe-container iframe").each(function () { $(".jupyter-notebook-iframe-container iframe").each(function () {
$(this).contents().find("head").append(cssLink); $(this).contents().find("head").append(cssLink);
if (theme == "dark") { if (jupyterTheme == "dark") {
$(this).bind("load", function () { $(this).bind("load", function () {
$(this).contents().find("body").attr({ $(this).contents().find("body").attr({
"data-jp-theme-light": "false", "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 // 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") { if (document.readyState === "interactive") {
let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0; let isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
let shortcutKeyElement = document.querySelector("#search-toggle .nav-link"); let shortcutKeyElement = document.querySelector("#search-toggle .nav-link");
@ -8,4 +8,4 @@ document.onreadystatechange = () => {
shortcutKeyElement.innerHTML = '&#x2318; k <i class="ti ti-search"></i>'; shortcutKeyElement.innerHTML = '&#x2318; k <i class="ti ti-search"></i>';
} }
} }
}; });