Mercurial > cpython-lru_cache-weakref
annotate Doc/tools/sphinxext/static/version_switch.js @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | ee33671b2c6a |
| children |
| rev | line source |
|---|---|
|
79994
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
1 (function() { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
2 'use strict'; |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
3 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
4 var all_versions = { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
5 '3.4': 'dev (3.4)', |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
6 '3.3': '3.3', |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
7 '3.2': '3.2', |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
8 '2.7': '2.7', |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
9 '2.6': '2.6' |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
10 }; |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
11 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
12 function build_select(current_version, current_release) { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
13 var buf = ['<select>']; |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
14 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
15 $.each(all_versions, function(version, title) { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
16 buf.push('<option value="' + version + '"'); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
17 if (version == current_version) |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
18 buf.push(' selected="selected">' + current_release + '</option>'); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
19 else |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
20 buf.push('>' + title + '</option>'); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
21 }); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
22 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
23 buf.push('</select>'); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
24 return buf.join(''); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
25 } |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
26 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
27 function patch_url(url, new_version) { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
28 var url_re = /\.org\/(\d|py3k|dev|((release\/)?\d\.\d[\w\d\.]*))\//, |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
29 new_url = url.replace(url_re, '.org/' + new_version + '/'); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
30 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
31 if (new_url == url && !new_url.match(url_re)) { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
32 // python 2 url without version? |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
33 new_url = url.replace(/\.org\//, '.org/' + new_version + '/'); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
34 } |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
35 return new_url; |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
36 } |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
37 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
38 function on_switch() { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
39 var selected = $(this).children('option:selected').attr('value'); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
40 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
41 var url = window.location.href, |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
42 new_url = patch_url(url, selected); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
43 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
44 if (new_url != url) { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
45 // check beforehand if url exists, else redirect to version's start page |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
46 $.ajax({ |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
47 url: new_url, |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
48 success: function() { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
49 window.location.href = new_url; |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
50 }, |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
51 error: function() { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
52 window.location.href = 'http://docs.python.org/' + selected; |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
53 } |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
54 }); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
55 } |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
56 } |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
57 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
58 $(document).ready(function() { |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
59 var release = DOCUMENTATION_OPTIONS.VERSION; |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
60 var version = release.substr(0, 3); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
61 var select = build_select(version, release); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
62 |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
63 $('.version_switcher_placeholder').html(select); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
64 $('.version_switcher_placeholder select').bind('change', on_switch); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
65 }); |
|
4a17784f2fee
#8040: port versionswitcher patch to 2.6.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
66 })(); |
