14
function build_select(current_version, current_release) {
15
var buf = ['<select>'];
17
$.each(all_versions, function(version, title) {
18
buf.push('<option value="' + version + '"');
19
if (version == current_version)
20
buf.push(' selected="selected">' + current_release + '</option>');
22
buf.push('>' + title + '</option>');
25
buf.push('</select>');
29
function patch_url(url, new_version) {
30
var url_re = /\.org\/(\d|py3k|dev|((release\/)?\d\.\d[\w\d\.]*))\//,
31
new_url = url.replace(url_re, '.org/' + new_version + '/');
33
if (new_url == url && !new_url.match(url_re)) {
34
// python 2 url without version?
35
new_url = url.replace(/\.org\//, '.org/' + new_version + '/');
40
function on_switch() {
41
var selected = $(this).children('option:selected').attr('value');
43
var url = window.location.href,
44
new_url = patch_url(url, selected);
47
// check beforehand if url exists, else redirect to version's start page
51
window.location.href = new_url;
54
window.location.href = 'https://docs.python.org/' + selected;
60
$(document).ready(function() {
61
var release = DOCUMENTATION_OPTIONS.VERSION;
62
var version = release.substr(0, 3);
63
var select = build_select(version, release);
65
$('.version_switcher_placeholder').html(select);
66
$('.version_switcher_placeholder select').bind('change', on_switch);