From b595b4ce2e6b24d8edbd73ca7738730636562a65 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 da9ed5710..82b08f22f 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 bfcaa684b..aef90658a 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 62081df90..fa121cddd 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 1e5dac23e..7d721b363 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 cbb70722b..2180ee4d3 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 9fb914b50..7ca25813a 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 5efab8d8d..77d9d9a4a 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 bea7413f8..fc6a4f5ee 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 19c585e00..235236f9c 100644 --- a/tests/test_build/sidebar_subpage.html +++ b/tests/test_build/sidebar_subpage.html @@ -33,15 +33,11 @@