-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maint: do not use document.write (#1921)
Co-authored-by: gabalafou <[email protected]>
- Loading branch information
Showing
10 changed files
with
84 additions
and
102 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
19 changes: 9 additions & 10 deletions
19
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,10 @@ | ||
{# 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> | ||
{# | ||
As this function will only work when JavaScript is enabled, | ||
we add a class that will hide it if js is disable. | ||
#} | ||
<button class="btn search-button-field search-button__button pst-js-only" 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 pst-js-only #} | ||
<button class="btn btn-sm pst-navbar-icon search-button search-button__button pst-js-only" 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 `pst-js-only`. #} | ||
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" 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 pst-js-only #} | ||
<div class="version-switcher__container dropdown pst-js-only"> | ||
<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
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,11 @@ | ||
<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> | ||
`); | ||
</script> | ||
<div class="version-switcher__container dropdown pst-js-only"> | ||
<button aria-controls="pst-version-switcher-list-2" aria-haspopup="listbox" aria-label="Version switcher list" class="version-switcher__button btn btn-sm dropdown-toggle" data-bs-toggle="dropdown" id="pst-version-switcher-button-2" type="button"> | ||
Choose version | ||
<!-- this text may get changed later by javascript --> | ||
<span class="caret"> | ||
</span> | ||
</button> | ||
<div aria-labelledby="pst-version-switcher-button-2" class="version-switcher__menu dropdown-menu list-group-flush py-0" id="pst-version-switcher-list-2" role="listbox"> | ||
<!-- dropdown will be populated by javascript on page load --> | ||
</div> | ||
</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,8 @@ | ||
<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 aria-label="light/dark" class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" data-bs-placement="bottom" data-bs-toggle="tooltip" title="light/dark"> | ||
<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