From 534e117c439980ca6efa445742ff122ffd92db7b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 25 May 2024 14:49:07 +0300 Subject: [PATCH 1/3] Move inline JavaScript to own file to reduce duplication --- Doc/tools/static/rtd_switcher.js | 82 ++++++++++++++++++++++++++++++ Doc/tools/templates/layout.html | 85 +------------------------------- 2 files changed, 83 insertions(+), 84 deletions(-) create mode 100644 Doc/tools/static/rtd_switcher.js diff --git a/Doc/tools/static/rtd_switcher.js b/Doc/tools/static/rtd_switcher.js new file mode 100644 index 00000000000000..78cbd77e44ad8d --- /dev/null +++ b/Doc/tools/static/rtd_switcher.js @@ -0,0 +1,82 @@ + function onSwitch(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() + + // Add some mocked hardcoded versions pointing to the official + // documentation while migrating to Read the Docs. + // These are only for testing purposes. + // TODO: remove them when managing all the versions on Read the Docs, + // since all the "active, built and not hidden" versions will be shown automatically. + let versions = config.versions.active.concat([ + { + slug: "dev (3.13)", + urls: { + documentation: "https://docs.python.org/3.13/", + } + }, + { + slug: "3.12", + urls: { + documentation: "https://docs.python.org/3.12/", + } + }, + { + slug: "3.11", + urls: { + documentation: "https://docs.python.org/3.11/", + } + }, + ]); + + const versionSelect = ` + + `; + + // Prepend 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 = ` + + `; + + // Query all the placeholders because there are different ones for Desktop/Mobile + const versionPlaceholders = document.querySelectorAll(".version_switcher_placeholder"); + for (placeholder of versionPlaceholders) { + placeholder.innerHTML = versionSelect; + let selectElement = placeholder.querySelector("select"); + selectElement.addEventListener("change", onSwitch); + } + + const languagePlaceholders = document.querySelectorAll(".language_switcher_placeholder"); + for (placeholder of languagePlaceholders) { + placeholder.innerHTML = languageSelect; + let selectElement = placeholder.querySelector("select"); + selectElement.addEventListener("change", onSwitch); + } + }); diff --git a/Doc/tools/templates/layout.html b/Doc/tools/templates/layout.html index e931147813ae03..02f19461fe6952 100644 --- a/Doc/tools/templates/layout.html +++ b/Doc/tools/templates/layout.html @@ -43,90 +43,7 @@ {{ super() }} {%- if not embedded %} + - {%- endif %} {% endblock %} From 622fdc75a36274250be1945d021b36d488ffe025 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 25 May 2024 18:53:55 +0300 Subject: [PATCH 2/3] Update indent to match existing --- Doc/tools/templates/layout.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/tools/templates/layout.html b/Doc/tools/templates/layout.html index 02f19461fe6952..3f88fc8e91faad 100644 --- a/Doc/tools/templates/layout.html +++ b/Doc/tools/templates/layout.html @@ -43,7 +43,7 @@ {{ super() }} {%- if not embedded %} - - + + {%- endif %} {% endblock %} From 6ad01db615ed49de6416fdf99ba9db980db6c018 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 27 May 2024 16:52:49 +0300 Subject: [PATCH 3/3] Fix indent --- Doc/tools/static/rtd_switcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tools/static/rtd_switcher.js b/Doc/tools/static/rtd_switcher.js index 75cbe48a6927cb..a67bb85505a9ca 100644 --- a/Doc/tools/static/rtd_switcher.js +++ b/Doc/tools/static/rtd_switcher.js @@ -19,7 +19,7 @@ documentation: "https://docs.python.org/3.14/", } }, - { + { slug: "dev (3.13)", urls: { documentation: "https://docs.python.org/3.13/", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy