Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8630c1e

Browse files
committed
#8040: merge with 3.2.
2 parents c4b8e05 + 380ce65 commit 8630c1e

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

Doc/tools/sphinxext/layout.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
<li><img src="{{ pathto('_static/py.png', 1) }}" alt=""
44
style="vertical-align: middle; margin-top: -1px"/></li>
55
<li><a href="http://www.python.org/">Python</a>{{ reldelim1 }}</li>
6-
<li><a href="{{ pathto('index') }}">{{ shorttitle }}</a>{{ reldelim1 }}</li>
6+
<li>
7+
{%- if versionswitcher is defined %}
8+
<span class="version_switcher_placeholder">{{ release }}</span>
9+
<a href="{{ pathto('index') }}">Documentation</a>{{ reldelim1 }}
10+
{%- else %}
11+
<a href="{{ pathto('index') }}">{{ shorttitle }}</a>{{ reldelim1 }}
12+
{%- endif %}
13+
</li>
714
{% endblock %}
815
{% block extrahead %}
916
<link rel="shortcut icon" type="image/png" href="{{ pathto('_static/py.png', 1) }}" />
1017
{% if not embedded %}<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>{% endif %}
18+
{% if versionswitcher is defined and not embedded %}<script type="text/javascript" src="{{ pathto('_static/version_switch.js', 1) }}"></script>{% endif %}
1119
{% if pagename == 'whatsnew/changelog' %}
1220
<script type="text/javascript">
1321
$(document).ready(function() {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
(function() {
2+
'use strict';
3+
4+
var all_versions = {
5+
'3.4': 'dev (3.4)',
6+
'3.3': '3.3',
7+
'3.2': '3.2',
8+
'2.7': '2.7',
9+
'2.6': '2.6'
10+
};
11+
12+
function build_select(current_version, current_release) {
13+
var buf = ['<select>'];
14+
15+
$.each(all_versions, function(version, title) {
16+
buf.push('<option value="' + version + '"');
17+
if (version == current_version)
18+
buf.push(' selected="selected">' + current_release + '</option>');
19+
else
20+
buf.push('>' + title + '</option>');
21+
});
22+
23+
buf.push('</select>');
24+
return buf.join('');
25+
}
26+
27+
function patch_url(url, new_version) {
28+
var url_re = /\.org\/(\d|py3k|dev|((release\/)?\d\.\d[\w\d\.]*))\//,
29+
new_url = url.replace(url_re, '.org/' + new_version + '/');
30+
31+
if (new_url == url && !new_url.match(url_re)) {
32+
// python 2 url without version?
33+
new_url = url.replace(/\.org\//, '.org/' + new_version + '/');
34+
}
35+
return new_url;
36+
}
37+
38+
function on_switch() {
39+
var selected = $(this).children('option:selected').attr('value');
40+
41+
var url = window.location.href,
42+
new_url = patch_url(url, selected);
43+
44+
if (new_url != url) {
45+
// check beforehand if url exists, else redirect to version's start page
46+
$.get(new_url, function() {
47+
window.location.href = new_url;
48+
}).error(function() {
49+
window.location.href = 'http://docs.python.org/' + selected;
50+
});
51+
}
52+
}
53+
54+
$(document).ready(function() {
55+
var select = build_select(DOCUMENTATION_OPTIONS.VERSION,
56+
DOCUMENTATION_OPTIONS.RELEASE);
57+
$('.version_switcher_placeholder').html(select);
58+
$('.version_switcher_placeholder select').bind('change', on_switch);
59+
});
60+
})();

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ Build
174174
Documentation
175175
-------------
176176

177+
- Issue #8040: added a version switcher to the documentation. Patch by
178+
Yury Selivanov.
179+
177180
- Additional comments and some style changes in the concurrent.futures URL
178181
retrieval example
179182

0 commit comments

Comments
 (0)