From c3d70066b1ff5b54aa2ba1e85c1b90ff1648cab6 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Tue, 9 Jul 2024 11:39:06 +0200 Subject: [PATCH] Maint: do not use document.write See #1920, this removes every usage of document.write in favor of display:none with a noscript tag. I did have to be a little more specific for buttons as the css rule in boostrap were overwriting the *.jsonly. Note that this does not solves #1920 as some things (like the more dropdown in nav bar) still require JS to work. --- .../components/navbar-logo.html | 2 +- .../components/search-button-field.html | 14 +++---- .../components/search-button.html | 9 ++--- .../components/theme-switcher.html | 16 +++----- .../components/version-switcher.html | 40 +++++++++---------- .../theme/pydata_sphinx_theme/layout.html | 9 +++++ tests/test_build/navbar_switcher.html | 38 ++++++++---------- tests/test_build/navbar_theme.html | 14 +++---- tests/test_build/sidebar_subpage.html | 14 +++---- 9 files changed, 69 insertions(+), 87 deletions(-) diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-logo.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-logo.html index da9ed57103..82b08f22f4 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-logo.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/navbar-logo.html @@ -28,7 +28,7 @@ {% endif %} {% set js_mode = "light" if default_mode == "dark" else "dark" %} {{ alt }} - + {{ alt }} {% endif %} {% if not is_logo or theme_logo.get("text") %}

{{ theme_logo.get("text") or docstitle }}

diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button-field.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button-field.html index bfcaa684b7..aef90658a3 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button-field.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button-field.html @@ -1,11 +1,7 @@ {# Displays a search field image that opens a search overlay when clicked. #} {# As this function will only work when JavaScript is enabled, we add it through JavaScript. #} - + diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button.html index 62081df90e..fa121cddda 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button.html @@ -1,9 +1,6 @@ {# Displays a magnifying glass icon that opens a search overlay when clicked. #} -{# As this function will only work when JavaScript is enabled, we add it through JavaScript. #} - diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-switcher.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-switcher.html index 1e5dac23ed..7d721b363c 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-switcher.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-switcher.html @@ -1,11 +1,7 @@ {# Displays an icon to switch between light mode, dark mode, and auto (use browser's setting). #} -{# As the theme switcher will only work when JavaScript is enabled, we add it through JavaScript. #} - +{# As the theme switcher will only work when JavaScript is enabled, we hide it with `jsonly`. #} + diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html index cbb70722b0..2180ee4d3f 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html @@ -1,26 +1,22 @@ {# Displays a dropdown box for switching among different versions of your documentation. #} {%- set button_id = unique_html_id("pst-version-switcher-button") -%} {%- set dropdown_id = unique_html_id("pst-version-switcher-list") -%} -{# As the version switcher will only work when JavaScript is enabled, we add it through JavaScript. #} - + diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html index 9fb914b50f..7ca25813a4 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html @@ -17,6 +17,15 @@ document.documentElement.dataset.mode = localStorage.getItem("mode") || "{{ default_mode }}"; document.documentElement.dataset.theme = localStorage.getItem("theme") || "{{ default_mode }}"; + + {{ _webpack.head_pre_assets() }} {{ _webpack.head_pre_icons() }} {{- css() }} diff --git a/tests/test_build/navbar_switcher.html b/tests/test_build/navbar_switcher.html index 5efab8d8da..77d9d9a4a3 100644 --- a/tests/test_build/navbar_switcher.html +++ b/tests/test_build/navbar_switcher.html @@ -1,22 +1,18 @@ - + diff --git a/tests/test_build/navbar_theme.html b/tests/test_build/navbar_theme.html index bea7413f8c..fc6a4f5eef 100644 --- a/tests/test_build/navbar_theme.html +++ b/tests/test_build/navbar_theme.html @@ -1,9 +1,5 @@ - + diff --git a/tests/test_build/sidebar_subpage.html b/tests/test_build/sidebar_subpage.html index 19c585e000..235236f9ca 100644 --- a/tests/test_build/sidebar_subpage.html +++ b/tests/test_build/sidebar_subpage.html @@ -33,15 +33,11 @@