diff options
author | Julien Palard <julien@palard.fr> | 2017-08-08 14:13:53 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-08-08 14:13:53 +0200 |
commit | e93135dbb265e801c0000a19cd9c5428d57d1cf4 (patch) | |
tree | 44c138c0c6e7999e86ede4268cdc5156fa388ad3 /Doc/tools/static/version_switch.js | |
parent | 9d7d928b5853b921ed27f1e535dfe8174169854c (diff) | |
download | cpython-git-e93135dbb265e801c0000a19cd9c5428d57d1cf4.tar.gz |
bpo-31045: Language switch (#2652) (#3023)
* Doc: Indicate the language
* Renaming version_switcher to switchers (to add language_switcher).
* Adding language switch.
* Doc switchers: Enhance readability of regex parsing versions.
* Doc switchers: Desambiguate the need of a replace(/\/+$/g, '') by proper naming.
* Doc switchers: py3k can't reach js, it's redirected server-side by nginx.
* Doc switchers: Examples matching actual regexes.
* Doc switchers: Better fallback on unexisting translated version.
(cherry picked from commit dff9b5f9d62aa0b23f8a255867d09d11890efd1b)
Diffstat (limited to 'Doc/tools/static/version_switch.js')
-rw-r--r-- | Doc/tools/static/version_switch.js | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/Doc/tools/static/version_switch.js b/Doc/tools/static/version_switch.js deleted file mode 100644 index 8b36a61671..0000000000 --- a/Doc/tools/static/version_switch.js +++ /dev/null @@ -1,67 +0,0 @@ -(function() { - 'use strict'; - - var all_versions = { - '3.7': 'dev (3.7)', - '3.6': '3.6', - '3.5': '3.5', - '3.4': '3.4', - '3.3': '3.3', - '2.7': '2.7', - }; - - function build_select(current_version, current_release) { - var buf = ['<select>']; - - $.each(all_versions, function(version, title) { - buf.push('<option value="' + version + '"'); - if (version == current_version) - buf.push(' selected="selected">' + current_release + '</option>'); - else - buf.push('>' + title + '</option>'); - }); - - buf.push('</select>'); - return buf.join(''); - } - - function patch_url(url, new_version) { - var url_re = /\.org\/(\d|py3k|dev|((release\/)?\d\.\d[\w\d\.]*))\//, - new_url = url.replace(url_re, '.org/' + new_version + '/'); - - if (new_url == url && !new_url.match(url_re)) { - // python 2 url without version? - new_url = url.replace(/\.org\//, '.org/' + new_version + '/'); - } - return new_url; - } - - function on_switch() { - var selected = $(this).children('option:selected').attr('value'); - - var url = window.location.href, - new_url = patch_url(url, selected); - - if (new_url != url) { - // check beforehand if url exists, else redirect to version's start page - $.ajax({ - url: new_url, - success: function() { - window.location.href = new_url; - }, - error: function() { - window.location.href = 'https://docs.python.org/' + selected; - } - }); - } - } - - $(document).ready(function() { - var release = DOCUMENTATION_OPTIONS.VERSION; - var version = release.substr(0, 3); - var select = build_select(version, release); - - $('.version_switcher_placeholder').html(select); - $('.version_switcher_placeholder select').bind('change', on_switch); - }); -})(); |