From fa4bcdc4a67589cd9a19223a1d5842c515951a3d Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 9 Apr 2013 21:40:37 +0200 Subject: New (py3k) theme --- doc/source/theme/static/version_switch.js | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 doc/source/theme/static/version_switch.js (limited to 'doc/source/theme/static/version_switch.js') diff --git a/doc/source/theme/static/version_switch.js b/doc/source/theme/static/version_switch.js new file mode 100644 index 00000000..cc7be1c5 --- /dev/null +++ b/doc/source/theme/static/version_switch.js @@ -0,0 +1,66 @@ +(function() { + 'use strict'; + + var all_versions = { + '3.4': 'dev (3.4)', + '3.3': '3.3', + '3.2': '3.2', + '2.7': '2.7', + '2.6': '2.6' + }; + + function build_select(current_version, current_release) { + var buf = [''); + 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 = 'http://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); + }); +})(); -- cgit v1.2.3