forked from pydata/pydata-sphinx-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See pydata#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 pydata#1920 as some things (like the more dropdown in nav bar) still require JS to work.
- Loading branch information
Showing
9 changed files
with
69 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 5 additions & 9 deletions
14
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button-field.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. #} | ||
<script> | ||
document.write(` | ||
<button class="btn search-button-field search-button__button" title="{{ _('Search') }}" aria-label="{{ _('Search') }}" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
<i class="fa-solid fa-magnifying-glass"></i> | ||
<span class="search-button__default-text">{{ _('Search') }}</span> | ||
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span> | ||
</button> | ||
`); | ||
</script> | ||
<button class="btn search-button-field search-button__button jsonly" title="{{ _('Search') }}" aria-label="{{ _('Search') }}" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
<i class="fa-solid fa-magnifying-glass"></i> | ||
<span class="search-button__default-text">{{ _('Search') }}</span> | ||
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span> | ||
</button> |
9 changes: 3 additions & 6 deletions
9
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/search-button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. #} | ||
<script> | ||
document.write(` | ||
<button class="btn btn-sm pst-navbar-icon search-button search-button__button" title="{{ _('Search') }}" aria-label="{{ _('Search') }}" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
{# As this function will only work when JavaScript is enabled, we hide it with jsonly #} | ||
<button class="btn btn-sm pst-navbar-icon search-button search-button__button jsonly" title="{{ _('Search') }}" aria-label="{{ _('Search') }}" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
<i class="fa-solid fa-magnifying-glass fa-lg"></i> | ||
</button> | ||
</button> | ||
`); | ||
</script> |
16 changes: 6 additions & 10 deletions
16
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/theme-switcher.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. #} | ||
<script> | ||
document.write(` | ||
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button" title="{{ _('light/dark') }}" aria-label="{{ _('light/dark') }}" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i> | ||
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i> | ||
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i> | ||
</button> | ||
`); | ||
</script> | ||
{# As the theme switcher will only work when JavaScript is enabled, we hide it with `jsonly`. #} | ||
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button jsonly" title="{{ _('light/dark') }}" aria-label="{{ _('light/dark') }}" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i> | ||
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i> | ||
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i> | ||
</button> |
40 changes: 18 additions & 22 deletions
40
src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. #} | ||
<script> | ||
document.write(` | ||
<div class="version-switcher__container dropdown"> | ||
<button id="{{ button_id }}" | ||
type="button" | ||
class="version-switcher__button btn btn-sm dropdown-toggle" | ||
data-bs-toggle="dropdown" | ||
aria-haspopup="listbox" | ||
aria-controls="{{ dropdown_id }}" | ||
aria-label="Version switcher list" | ||
> | ||
Choose version <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div id="{{ dropdown_id }}" | ||
class="version-switcher__menu dropdown-menu list-group-flush py-0" | ||
role="listbox" aria-labelledby="{{ button_id }}"> | ||
<!-- dropdown will be populated by javascript on page load --> | ||
</div> | ||
{# As the version switcher will only work when JavaScript is enabled, we hide it with jsonly #} | ||
<div class="version-switcher__container dropdown jsonly"> | ||
<button id="{{ button_id }}" | ||
type="button" | ||
class="version-switcher__button btn btn-sm dropdown-toggle" | ||
data-bs-toggle="dropdown" | ||
aria-haspopup="listbox" | ||
aria-controls="{{ dropdown_id }}" | ||
aria-label="Version switcher list" | ||
> | ||
Choose version <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div id="{{ dropdown_id }}" | ||
class="version-switcher__menu dropdown-menu list-group-flush py-0" | ||
role="listbox" aria-labelledby="{{ button_id }}"> | ||
<!-- dropdown will be populated by javascript on page load --> | ||
</div> | ||
`); | ||
</script> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
<script> | ||
document.write(` | ||
<div class="version-switcher__container dropdown"> | ||
<button id="pst-version-switcher-button-2" | ||
type="button" | ||
class="version-switcher__button btn btn-sm dropdown-toggle" | ||
data-bs-toggle="dropdown" | ||
aria-haspopup="listbox" | ||
aria-controls="pst-version-switcher-list-2" | ||
aria-label="Version switcher list" | ||
> | ||
Choose version <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div id="pst-version-switcher-list-2" | ||
class="version-switcher__menu dropdown-menu list-group-flush py-0" | ||
role="listbox" aria-labelledby="pst-version-switcher-button-2"> | ||
<!-- dropdown will be populated by javascript on page load --> | ||
</div> | ||
<div class="version-switcher__container dropdown jsonly"> | ||
<button id="pst-version-switcher-button-2" | ||
type="button" | ||
class="version-switcher__button btn btn-sm dropdown-toggle" | ||
data-bs-toggle="dropdown" | ||
aria-haspopup="listbox" | ||
aria-controls="pst-version-switcher-list-2" | ||
aria-label="Version switcher list" | ||
> | ||
Choose version <!-- this text may get changed later by javascript --> | ||
<span class="caret"></span> | ||
</button> | ||
<div id="pst-version-switcher-list-2" | ||
class="version-switcher__menu dropdown-menu list-group-flush py-0" | ||
role="listbox" aria-labelledby="pst-version-switcher-button-2"> | ||
<!-- dropdown will be populated by javascript on page load --> | ||
</div> | ||
`); | ||
</script> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
<script> | ||
document.write(` | ||
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i> | ||
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i> | ||
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i> | ||
</button> | ||
`); | ||
</script> | ||
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button jsonly" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip"> | ||
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i> | ||
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i> | ||
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i> | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters