mirror of
https://github.com/readthedocs/sphinx_rtd_theme.git
synced 2025-02-25 18:55:21 -06:00
Show version/language selectors below the title (#1601)
* Show version/language selectors below the title * Use CSS styles from old attempt https://github.com/readthedocs/sphinx_rtd_theme/pull/438 * Update CSS to apply to both selectors * Prepend the current version if it's hidden * Split it into two different configs * Use correct value for language * Make the selectors more prominent * Typo fix on comment * Update CSS * Update JavaScript * Always include the version javascript * Only include the languages if there is one * Change `display_version` default * HTML layout rework * Update docs * HTML layout fix * Docs typo * Update CSS * Updates from review * re-compile CSS * Update CSS * Apply suggestions from code review Co-authored-by: Eric Holscher <25510+ericholscher@users.noreply.github.com> * Use the prettier to lint the file * Whitespaces * Update event listener * Update CSS * Update CSS * Remove language switch if there are not translations * Tune version and language selector styles (#1603) * Tuning on select width and icon placement * Use better cursor * Add a max width to selects so that they can't overflow * Only add after pseudo element if select exists * Lint * Debug: trigger Read the Docs Addons event to test/debug locally (#1606) * Debug: trigger Read the Docs Addons event to test/debug locally Closes #1605 * Push missing file --------- Co-authored-by: Eric Holscher <25510+ericholscher@users.noreply.github.com> Co-authored-by: Anthony <aj@ohess.org>
This commit is contained in:
parent
9c75444a73
commit
4cab02fff8
369
docs/_static/addons.mocked.json
vendored
Normal file
369
docs/_static/addons.mocked.json
vendored
Normal file
@ -0,0 +1,369 @@
|
||||
{
|
||||
"addons": {
|
||||
"analytics": {
|
||||
"code": null,
|
||||
"enabled": true
|
||||
},
|
||||
"ethicalads": {
|
||||
"ad_free": false,
|
||||
"campaign_types": [
|
||||
"community",
|
||||
"house",
|
||||
"paid"
|
||||
],
|
||||
"enabled": true,
|
||||
"keywords": [
|
||||
"only words"
|
||||
],
|
||||
"publisher": "readthedocs"
|
||||
},
|
||||
"external_version_warning": {
|
||||
"enabled": true
|
||||
},
|
||||
"flyout": {
|
||||
"enabled": true
|
||||
},
|
||||
"hotkeys": {
|
||||
"doc_diff": {
|
||||
"enabled": true,
|
||||
"trigger": "KeyD"
|
||||
},
|
||||
"enabled": true,
|
||||
"search": {
|
||||
"enabled": true,
|
||||
"trigger": "Slash"
|
||||
}
|
||||
},
|
||||
"non_latest_version_warning": {
|
||||
"enabled": true
|
||||
},
|
||||
"search": {
|
||||
"default_filter": "project:sphinx-rtd-theme/stable",
|
||||
"enabled": true,
|
||||
"filters": [
|
||||
[
|
||||
"Include subprojects",
|
||||
"subprojects:sphinx-rtd-theme/stable"
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"api_version": "1",
|
||||
"builds": {
|
||||
"current": {
|
||||
"commit": "7c9b1b5d391f6d7fae72274393eb25d1df96e546",
|
||||
"created": "2023-11-28T04:14:06.510677Z",
|
||||
"duration": 42,
|
||||
"error": "",
|
||||
"finished": "2023-11-28T04:14:48.510Z",
|
||||
"id": 22677856,
|
||||
"project": "sphinx-rtd-theme",
|
||||
"state": {
|
||||
"code": "finished",
|
||||
"name": "Finished"
|
||||
},
|
||||
"success": true,
|
||||
"urls": {
|
||||
"build": "https://readthedocs.org/projects/sphinx-rtd-theme/builds/22677856/",
|
||||
"project": "https://readthedocs.org/projects/sphinx-rtd-theme/",
|
||||
"version": "https://readthedocs.org/projects/sphinx-rtd-theme/version/stable/edit/"
|
||||
},
|
||||
"version": "stable"
|
||||
}
|
||||
},
|
||||
"domains": {
|
||||
"dashboard": "readthedocs.org"
|
||||
},
|
||||
"projects": {
|
||||
"current": {
|
||||
"created": "2017-12-21T04:04:42.561793Z",
|
||||
"default_branch": "master",
|
||||
"default_version": "stable",
|
||||
"external_builds_privacy_level": "public",
|
||||
"homepage": null,
|
||||
"id": 170010,
|
||||
"language": {
|
||||
"code": "en",
|
||||
"name": "English"
|
||||
},
|
||||
"modified": "2021-03-16T17:13:52.465051Z",
|
||||
"name": "sphinx_rtd_theme",
|
||||
"privacy_level": "public",
|
||||
"programming_language": {
|
||||
"code": "words",
|
||||
"name": "Only Words"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/readthedocs/sphinx_rtd_theme"
|
||||
},
|
||||
"single_version": false,
|
||||
"slug": "sphinx-rtd-theme",
|
||||
"subproject_of": null,
|
||||
"tags": [],
|
||||
"translation_of": null,
|
||||
"urls": {
|
||||
"builds": "https://readthedocs.org/projects/sphinx-rtd-theme/builds/",
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/stable/",
|
||||
"downloads": "https://readthedocs.org/projects/sphinx-rtd-theme/downloads/",
|
||||
"home": "https://readthedocs.org/projects/sphinx-rtd-theme/",
|
||||
"versions": "https://readthedocs.org/projects/sphinx-rtd-theme/versions/"
|
||||
},
|
||||
"users": [
|
||||
{
|
||||
"username": "eric"
|
||||
},
|
||||
{
|
||||
"username": "humitos"
|
||||
},
|
||||
{
|
||||
"username": "agj"
|
||||
}
|
||||
],
|
||||
"versioning_scheme": "multiple_versions_with_translations"
|
||||
},
|
||||
"translations": []
|
||||
},
|
||||
"readthedocs": {
|
||||
"analytics": {
|
||||
"code": null
|
||||
}
|
||||
},
|
||||
"versions": {
|
||||
"active": [
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 6692534,
|
||||
"identifier": "b07560bf97dad3a4266f6145bd4b662ac708ab00",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "0.5.2",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/0.5.2/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/0.5.2/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/0.5.2/"
|
||||
},
|
||||
"verbose_name": "0.5.2"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 7273098,
|
||||
"identifier": "c9b1bde560d8ee31400e4e4f92f2e8d7a42265ce",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "1.0.0",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/1.0.0/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/1.0.0/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/1.0.0/"
|
||||
},
|
||||
"verbose_name": "1.0.0"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 10496721,
|
||||
"identifier": "f854c890e1445b99a43ac5f10463a5df83739a2e",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "1.1.1",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/1.1.1/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/1.1.1/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/1.1.1/"
|
||||
},
|
||||
"verbose_name": "1.1.1"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 16340532,
|
||||
"identifier": "9899ee4ee2f547f81e51297dc12317f018e62fdd",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "1.2.2",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/1.2.2/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/1.2.2/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/1.2.2/"
|
||||
},
|
||||
"verbose_name": "1.2.2"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 17681643,
|
||||
"identifier": "15ed4de08de55f7066ff4f2ac39883a397db30d3",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "1.3.0",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/1.3.0/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/1.3.0/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/1.3.0/"
|
||||
},
|
||||
"verbose_name": "1.3.0"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 18862205,
|
||||
"identifier": "7c9b1b5d391f6d7fae72274393eb25d1df96e546",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "2.0.0",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/2.0.0/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/2.0.0/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/2.0.0/"
|
||||
},
|
||||
"verbose_name": "2.0.0"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 18862205,
|
||||
"identifier": "7c9b1b5d391f6d7fae72274393eb25d1df96e546",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "2.0.0",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/2.0.0/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/2.0.0/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/2.0.0/"
|
||||
},
|
||||
"verbose_name": "2.0.0"
|
||||
}
|
||||
],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 3271725,
|
||||
"identifier": "7c9b1b5d391f6d7fae72274393eb25d1df96e546",
|
||||
"privacy_level": "public",
|
||||
"ref": "2.0.0",
|
||||
"slug": "stable",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/stable/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/stable/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/2.0.0/"
|
||||
},
|
||||
"verbose_name": "stable"
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 3271688,
|
||||
"identifier": "master",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "latest",
|
||||
"type": "branch",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/latest/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/latest/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/master/"
|
||||
},
|
||||
"verbose_name": "latest"
|
||||
}
|
||||
],
|
||||
"current": {
|
||||
"active": true,
|
||||
"aliases": [
|
||||
{
|
||||
"active": true,
|
||||
"aliases": [],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 18862205,
|
||||
"identifier": "7c9b1b5d391f6d7fae72274393eb25d1df96e546",
|
||||
"privacy_level": "public",
|
||||
"ref": null,
|
||||
"slug": "2.0.0",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/2.0.0/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/2.0.0/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/2.0.0/"
|
||||
},
|
||||
"verbose_name": "2.0.0"
|
||||
}
|
||||
],
|
||||
"built": true,
|
||||
"downloads": {},
|
||||
"hidden": false,
|
||||
"id": 3271725,
|
||||
"identifier": "7c9b1b5d391f6d7fae72274393eb25d1df96e546",
|
||||
"privacy_level": "public",
|
||||
"ref": "2.0.0",
|
||||
"slug": "stable",
|
||||
"type": "tag",
|
||||
"urls": {
|
||||
"dashboard": {
|
||||
"edit": "https://readthedocs.org/projects/sphinx-rtd-theme/version/stable/edit/"
|
||||
},
|
||||
"documentation": "https://sphinx-rtd-theme.readthedocs.io/en/stable/",
|
||||
"vcs": "https://github.com/readthedocs/sphinx_rtd_theme/tree/2.0.0/"
|
||||
},
|
||||
"verbose_name": "stable"
|
||||
}
|
||||
}
|
||||
}
|
38
docs/_static/debug.js
vendored
38
docs/_static/debug.js
vendored
@ -4,4 +4,40 @@ $(function () {
|
||||
$("[data-toggle='rst-debug-badge']").on("click", function () {
|
||||
$("[data-toggle='rst-versions']").toggleClass("rst-badge");
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
const EVENT_READTHEDOCS_ADDONS_DATA_READY = "readthedocs-addons-data-ready";
|
||||
|
||||
fetch("_static/addons.mocked.json", { method: "GET" })
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Error downloading Read the Docs Addons mocked data");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
return dispatchEvent(
|
||||
EVENT_READTHEDOCS_ADDONS_DATA_READY,
|
||||
new ReadTheDocsEventData(data),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
// ``ReadTheDocsEventData`` and ``dispatchEvent``
|
||||
// are borrowed and adapted from Read the Docs Addons.
|
||||
// https://github.com/readthedocs/addons
|
||||
class ReadTheDocsEventData {
|
||||
constructor(data) {
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
data() {
|
||||
return this._data;
|
||||
}
|
||||
}
|
||||
|
||||
function dispatchEvent(eventName, data) {
|
||||
const event = new CustomEvent(eventName, { detail: data });
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
55
docs/_templates/layout.html
vendored
55
docs/_templates/layout.html
vendored
@ -1,55 +0,0 @@
|
||||
{%- extends "!layout.html" %}
|
||||
|
||||
{#-
|
||||
|
||||
This template exists as a way to implement a version menu without changing what
|
||||
the theme normally renders the menu on local builds and on builds on Read the
|
||||
Docs. This is for local testing purposes only.
|
||||
|
||||
#}
|
||||
|
||||
{%- block footer %}
|
||||
{%- if not READTHEDOCS %}
|
||||
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="{{ _('Versions') }}">
|
||||
<span class="rst-current-version" data-toggle="rst-current-version">
|
||||
<span class="fa fa-book"> Read the Docs</span>
|
||||
v: latest
|
||||
<span class="fa fa-caret-down"></span>
|
||||
</span>
|
||||
<div class="rst-other-versions">
|
||||
<dl>
|
||||
<dt>{{ _('Versions') }}</dt>
|
||||
{%- if test_versions %}
|
||||
{%- for version in test_versions %}
|
||||
<dd><a href="#">{{ version }}</a></dd>
|
||||
{%- endfor %}
|
||||
{%- else %}
|
||||
<dd><a href="#">latest</a></dd>
|
||||
<dd><a href="#">1.0</a></dd>
|
||||
<dd><a href="#">1.1</a></dd>
|
||||
{%- endif %}
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{{ _('Downloads') }}</dt>
|
||||
<dd><a href="#">PDF</a></dd>
|
||||
<dd><a href="#">ePub</a></dd>
|
||||
<dd><a href="#">HTML</a></dd>
|
||||
</dl>
|
||||
<dl>
|
||||
{#- Translators: The phrase "Read the Docs" is not translated #}
|
||||
<dt>{{ _('On Read the Docs') }}</dt>
|
||||
<dd>
|
||||
<a href="#">{{ _('Project Home') }}</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="#">{{ _('Builds') }}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>Debug</dt>
|
||||
<dd><a href="#" data-toggle="rst-debug-badge">Swap badge position</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
{%- endif %}
|
||||
{%- endblock %}
|
@ -61,12 +61,7 @@ html_context = {}
|
||||
if not 'READTHEDOCS' in os.environ:
|
||||
html_static_path = ['_static/']
|
||||
html_js_files = ['debug.js']
|
||||
|
||||
# Add fake versions for local QA of the menu
|
||||
html_context['test_versions'] = list(map(
|
||||
lambda x: str(x / 10),
|
||||
range(1, 100)
|
||||
))
|
||||
html_context["DEBUG"] = True
|
||||
|
||||
html_logo = "demo/static/logo-wordmark-light.svg"
|
||||
html_show_sourcelink = True
|
||||
|
@ -16,12 +16,13 @@ For example:
|
||||
'analytics_id': 'G-XXXXXXXXXX', # Provided by Google in your dashboard
|
||||
'analytics_anonymize_ip': False,
|
||||
'logo_only': False,
|
||||
'display_version': True,
|
||||
'prev_next_buttons_location': 'bottom',
|
||||
'style_external_links': False,
|
||||
'vcs_pageview_mode': '',
|
||||
'style_nav_header_background': 'white',
|
||||
'flyout_display': 'hidden',
|
||||
'version_selector': True,
|
||||
'language_selector': True,
|
||||
# Toc options
|
||||
'collapse_navigation': True,
|
||||
'sticky_navigation': True,
|
||||
@ -139,7 +140,11 @@ Miscellaneous options
|
||||
If ``True``, the version number is shown at the top of the sidebar.
|
||||
|
||||
:type: boolean
|
||||
:default: ``True``
|
||||
:default: ``False``
|
||||
|
||||
.. deprecated:: 3.0.0
|
||||
|
||||
Removed in favor of ``version_selector`` and ``language_selector``.
|
||||
|
||||
.. confval:: logo_only
|
||||
|
||||
@ -192,6 +197,26 @@ Miscellaneous options
|
||||
:type: str
|
||||
:default: ``hidden``
|
||||
|
||||
.. confval:: version_selector
|
||||
|
||||
Display a version selector below the title.
|
||||
This feature makes usage of `Read the Docs Addons <https://docs.readthedocs.io/page/addons.html>`_ for this,
|
||||
so it's required the documentation to be hosted on Read the Docs.
|
||||
It only appears when there are more than 1 active version.
|
||||
|
||||
:type: boolean
|
||||
:default: ``True``
|
||||
|
||||
.. confval:: language_selector
|
||||
|
||||
Display a language selector below the title.
|
||||
This feature makes usage of `Read the Docs Addons <https://docs.readthedocs.io/page/addons.html>`_ for this,
|
||||
so it's required the documentation to be served on Read the Docs.
|
||||
It only appears when there is more than 1 active language.
|
||||
|
||||
:type: boolean
|
||||
:default: ``True``
|
||||
|
||||
|
||||
File-wide metadata
|
||||
==================
|
||||
|
@ -67,7 +67,7 @@
|
||||
{%- endfor %}
|
||||
<script src="{{ pathto('_static/js/theme.js', 1) }}"></script>
|
||||
|
||||
{%- if READTHEDOCS and theme_flyout_display != "hidden" %}
|
||||
{%- if READTHEDOCS or DEBUG %}
|
||||
<script src="{{ pathto('_static/js/versions.js', 1) }}"></script>
|
||||
{%- endif %}
|
||||
|
||||
@ -124,14 +124,11 @@
|
||||
{%- endif %}
|
||||
</a>
|
||||
|
||||
{%- if theme_display_version %}
|
||||
{%- set nav_version = version %}
|
||||
{%- if READTHEDOCS and current_version %}
|
||||
{%- set nav_version = current_version %}
|
||||
{%- endif %}
|
||||
{%- if nav_version %}
|
||||
<div class="version">
|
||||
{{ nav_version }}
|
||||
{%- if READTHEDOCS or DEBUG %}
|
||||
{%- if theme_version_selector or theme_language_selector %}
|
||||
<div class="switch-menus">
|
||||
<div class="version-switch"></div>
|
||||
<div class="language-switch"></div>
|
||||
</div>
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,21 +1,29 @@
|
||||
function renderLanguages(config) {
|
||||
if (!config.projects.translations.length) {
|
||||
return "";
|
||||
}
|
||||
const themeFlyoutDisplay = "{{ theme_flyout_display }}";
|
||||
const themeVersionSelector = "{{ theme_version_selector }}";
|
||||
const themeLanguageSelector = "{{ theme_language_selector }}";
|
||||
|
||||
const languagesHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Languages') }}</dt>
|
||||
${ config.projects.translations.map(
|
||||
(translation) => `
|
||||
<dd ${ translation.slug == config.projects.current.slug ? 'class="rtd-current-item"' : '' }>
|
||||
<a href="${ translation.urls.documentation }">${ translation.language.code }</a>
|
||||
</dd>
|
||||
`).join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return languagesHTML;
|
||||
}
|
||||
if (themeFlyoutDisplay === "attached") {
|
||||
function renderLanguages(config) {
|
||||
if (!config.projects.translations.length) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const languagesHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Languages') }}</dt>
|
||||
${config.projects.translations
|
||||
.map(
|
||||
(translation) => `
|
||||
<dd ${translation.slug == config.projects.current.slug ? 'class="rtd-current-item"' : ""}>
|
||||
<a href="${translation.urls.documentation}">${translation.language.code}</a>
|
||||
</dd>
|
||||
`,
|
||||
)
|
||||
.join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return languagesHTML;
|
||||
}
|
||||
|
||||
function renderVersions(config) {
|
||||
if (!config.versions.active.length) {
|
||||
@ -24,12 +32,15 @@ function renderLanguages(config) {
|
||||
const versionsHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Versions') }}</dt>
|
||||
${ config.versions.active.map(
|
||||
(version) => `
|
||||
<dd ${ version.slug === config.versions.current.slug ? 'class="rtd-current-item"' : '' }>
|
||||
<a href="${ version.urls.documentation }">${ version.slug }</a>
|
||||
${config.versions.active
|
||||
.map(
|
||||
(version) => `
|
||||
<dd ${version.slug === config.versions.current.slug ? 'class="rtd-current-item"' : ""}>
|
||||
<a href="${version.urls.documentation}">${version.slug}</a>
|
||||
</dd>
|
||||
`).join("\n")}
|
||||
`,
|
||||
)
|
||||
.join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return versionsHTML;
|
||||
@ -48,42 +59,45 @@ function renderLanguages(config) {
|
||||
const downloadsHTML = `
|
||||
<dl>
|
||||
<dt>{{ _('Downloads') }}</dt>
|
||||
${ Object.entries(config.versions.current.downloads).map(
|
||||
([name, url]) => `
|
||||
${Object.entries(config.versions.current.downloads)
|
||||
.map(
|
||||
([name, url]) => `
|
||||
<dd>
|
||||
<a href="${ url }">${ downloadsNameDisplay[name] }</a>
|
||||
<a href="${url}">${downloadsNameDisplay[name]}</a>
|
||||
</dd>
|
||||
`).join("\n")}
|
||||
`,
|
||||
)
|
||||
.join("\n")}
|
||||
</dl>
|
||||
`;
|
||||
return downloadsHTML;
|
||||
}
|
||||
|
||||
document.addEventListener("readthedocs-addons-data-ready", function(event) {
|
||||
document.addEventListener("readthedocs-addons-data-ready", function (event) {
|
||||
const config = event.detail.data();
|
||||
|
||||
const flyout = `
|
||||
<div class="rst-versions" data-toggle="rst-versions" role="note">
|
||||
<span class="rst-current-version" data-toggle="rst-current-version">
|
||||
<span class="fa fa-book"> Read the Docs</span>
|
||||
v: ${ config.versions.current.slug }
|
||||
v: ${config.versions.current.slug}
|
||||
<span class="fa fa-caret-down"></span>
|
||||
</span>
|
||||
<div class="rst-other-versions">
|
||||
<div class="injected">
|
||||
${ renderLanguages(config) }
|
||||
${ renderVersions(config) }
|
||||
${ renderDownloads(config) }
|
||||
${renderLanguages(config)}
|
||||
${renderVersions(config)}
|
||||
${renderDownloads(config)}
|
||||
<dl>
|
||||
<dt>{{ _('On Read the Docs') }}</dt>
|
||||
<dd>
|
||||
<a href="${ config.projects.current.urls.home }">{{ _('Project Home') }}</a>
|
||||
<a href="${config.projects.current.urls.home}">{{ _('Project Home') }}</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="${ config.projects.current.urls.builds }">{{ _('Builds') }}</a>
|
||||
<a href="${config.projects.current.urls.builds}">{{ _('Builds') }}</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="${ config.projects.current.urls.downloads }">{{ _('Downloads') }}</a>
|
||||
<a href="${config.projects.current.urls.downloads}">{{ _('Downloads') }}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
@ -112,14 +126,97 @@ function renderLanguages(config) {
|
||||
document.body.insertAdjacentHTML("beforeend", flyout);
|
||||
|
||||
// Trigger the Read the Docs Addons Search modal when clicking on the "Search docs" input from inside the flyout.
|
||||
document.querySelector("#flyout-search-form").addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
document
|
||||
.querySelector("#flyout-search-form")
|
||||
.addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
|
||||
// Trigger the Read the Docs Addons Search modal when clicking on "Search docs" input from the topnav.
|
||||
document.querySelector("[role='search'] input").addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
});
|
||||
document
|
||||
.querySelector("[role='search'] input")
|
||||
.addEventListener("focusin", () => {
|
||||
const event = new CustomEvent("readthedocs-search-show");
|
||||
document.dispatchEvent(event);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (themeLanguageSelector || themeVersionSelector) {
|
||||
function onSelectorSwitch(event) {
|
||||
const option = event.target.selectedIndex;
|
||||
const item = event.target.options[option];
|
||||
window.location.href = item.dataset.url;
|
||||
}
|
||||
|
||||
document.addEventListener("readthedocs-addons-data-ready", function (event) {
|
||||
const config = event.detail.data();
|
||||
|
||||
const versionSwitch = document.querySelector(
|
||||
"div.switch-menus > div.version-switch",
|
||||
);
|
||||
if (themeVersionSelector) {
|
||||
let versions = config.versions.active;
|
||||
if (config.versions.current.type === "external") {
|
||||
versions.unshift(config.versions.current);
|
||||
}
|
||||
const versionSelect = `
|
||||
<select>
|
||||
${versions
|
||||
.map(
|
||||
(version) => `
|
||||
<option
|
||||
value="${version.slug}"
|
||||
${config.versions.current.slug === version.slug ? 'selected="selected"' : ""}
|
||||
data-url="${version.urls.documentation}">
|
||||
${version.slug}
|
||||
</option>`,
|
||||
)
|
||||
.join("\n")}
|
||||
</select>
|
||||
`;
|
||||
|
||||
versionSwitch.innerHTML = versionSelect;
|
||||
versionSwitch.firstElementChild.addEventListener("change", onSelectorSwitch);
|
||||
}
|
||||
|
||||
const languageSwitch = document.querySelector(
|
||||
"div.switch-menus > div.language-switch",
|
||||
);
|
||||
|
||||
if (themeLanguageSelector) {
|
||||
if (config.projects.translations.length) {
|
||||
// Add the current language to the options on the selector
|
||||
let languages = config.projects.translations.concat(
|
||||
config.projects.current,
|
||||
);
|
||||
languages = languages.sort((a, b) =>
|
||||
a.language.name.localeCompare(b.language.name),
|
||||
);
|
||||
|
||||
const languageSelect = `
|
||||
<select>
|
||||
${languages
|
||||
.map(
|
||||
(language) => `
|
||||
<option
|
||||
value="${language.language.code}"
|
||||
${config.projects.current.slug === language.slug ? 'selected="selected"' : ""}
|
||||
data-url="${language.urls.documentation}">
|
||||
${language.language.name}
|
||||
</option>`,
|
||||
)
|
||||
.join("\n")}
|
||||
</select>
|
||||
`;
|
||||
|
||||
languageSwitch.innerHTML = languageSelect;
|
||||
languageSwitch.firstElementChild.addEventListener("change", onSelectorSwitch);
|
||||
}
|
||||
else {
|
||||
languageSwitch.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -13,9 +13,10 @@ navigation_depth = 4
|
||||
includehidden = True
|
||||
titles_only =
|
||||
logo_only =
|
||||
display_version = True
|
||||
prev_next_buttons_location = bottom
|
||||
style_external_links = False
|
||||
style_nav_header_background =
|
||||
vcs_pageview_mode =
|
||||
flyout_display = hidden
|
||||
version_selector = True
|
||||
language_selector = True
|
||||
|
@ -217,7 +217,7 @@ html
|
||||
padding: ($base-line-height / 6) ($base-line-height / 4)
|
||||
margin-bottom: $gutter / 2
|
||||
max-width: 100%
|
||||
&:hover
|
||||
&:hover, &active, &focus
|
||||
background: rgba(255, 255, 255, 0.1)
|
||||
img.logo
|
||||
display: block // display on its own line all the time
|
||||
@ -228,13 +228,55 @@ html
|
||||
max-width: 100% // shrink on mobile, if appropriate
|
||||
background: rgba(0, 0, 0, 0) // make hover background of parent show up properly
|
||||
&.icon
|
||||
display: block
|
||||
img.logo
|
||||
margin-top: 0.85em // space it away from the title text
|
||||
> div.version
|
||||
> div.switch-menus
|
||||
position: relative
|
||||
display: block
|
||||
margin-top: -1 * $gutter / 4
|
||||
margin-bottom: $gutter / 2
|
||||
font-weight: normal
|
||||
color: rgba(255, 255, 255, 0.3)
|
||||
color: rgba(255, 255,255, 0.3)
|
||||
> div.version-switch, > div.language-switch
|
||||
display: inline-block
|
||||
padding: .2em
|
||||
select
|
||||
// Provide room for dropdown icon
|
||||
display: inline-block
|
||||
margin-right: -2rem
|
||||
padding-right: 2rem
|
||||
max-width: $nav-desktop-width * .8
|
||||
// Alter base select styles
|
||||
text-align-last: center
|
||||
background: none
|
||||
border: none
|
||||
border-radius: 0em
|
||||
box-shadow: none
|
||||
font-family: $base-font-family
|
||||
font-size: 1em
|
||||
font-weight: normal
|
||||
color: rgba(255, 255, 255, .3)
|
||||
cursor: pointer
|
||||
// Allow for padding
|
||||
appearance: none
|
||||
-webkit-appearance: none
|
||||
-moz-appearance: none
|
||||
&:hover, &:active, &:focus
|
||||
background: rgba(255, 255, 255, .1)
|
||||
color: rgba(255, 255, 255, .5)
|
||||
&:has(> select):after
|
||||
display: inline-block
|
||||
width: 1.5em
|
||||
height: 100%
|
||||
padding: .1em
|
||||
content: "\f0d7"
|
||||
font-size: 1em
|
||||
line-height: 1.2em
|
||||
font-family: FontAwesome
|
||||
text-align: center
|
||||
pointer-events: none
|
||||
box-sizing: border-box
|
||||
|
||||
.wy-nav .wy-menu-vertical
|
||||
header
|
||||
|
Loading…
Reference in New Issue
Block a user