[Python-checkins] cpython (merge 3.3 -> default): #8040: merge with 3.3.

ezio.melotti python-checkins at python.org
Sat Oct 27 21:12:22 CEST 2012


http://hg.python.org/cpython/rev/9552d8b90683
changeset:   79978:9552d8b90683
parent:      79974:b21c28258d3c
parent:      79977:9505a34b4484
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sat Oct 27 22:11:57 2012 +0300
summary:
  #8040: merge with 3.3.

files:
  Doc/tools/sphinxext/layout.html              |  10 +-
  Doc/tools/sphinxext/static/version_switch.js |  60 ++++++++++
  Misc/NEWS                                    |   3 +
  3 files changed, 72 insertions(+), 1 deletions(-)


diff --git a/Doc/tools/sphinxext/layout.html b/Doc/tools/sphinxext/layout.html
--- a/Doc/tools/sphinxext/layout.html
+++ b/Doc/tools/sphinxext/layout.html
@@ -3,11 +3,19 @@
         <li><img src="{{ pathto('_static/py.png', 1) }}" alt=""
                  style="vertical-align: middle; margin-top: -1px"/></li>
         <li><a href="http://www.python.org/">Python</a>{{ reldelim1 }}</li>
-        <li><a href="{{ pathto('index') }}">{{ shorttitle }}</a>{{ reldelim1 }}</li>
+        <li>
+          {%- if versionswitcher is defined %}
+          <span class="version_switcher_placeholder">{{ release }}</span>
+          <a href="{{ pathto('index') }}">Documentation</a>{{ reldelim1 }}
+          {%- else %}
+          <a href="{{ pathto('index') }}">{{ shorttitle }}</a>{{ reldelim1 }}
+          {%- endif %}
+        </li>
 {% endblock %}
 {% block extrahead %}
     <link rel="shortcut icon" type="image/png" href="{{ pathto('_static/py.png', 1) }}" />
     {% if not embedded %}<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>{% endif %}
+    {% if versionswitcher is defined and not embedded %}<script type="text/javascript" src="{{ pathto('_static/version_switch.js', 1) }}"></script>{% endif %}
     {% if pagename == 'whatsnew/changelog' %}
     <script type="text/javascript">
       $(document).ready(function() {
diff --git a/Doc/tools/sphinxext/static/version_switch.js b/Doc/tools/sphinxext/static/version_switch.js
new file mode 100644
--- /dev/null
+++ b/Doc/tools/sphinxext/static/version_switch.js
@@ -0,0 +1,60 @@
+(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 = ['<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
+      $.get(new_url, function() {
+        window.location.href = new_url;
+      }).error(function() {
+        window.location.href = 'http://docs.python.org/' + selected;
+      });
+    }
+  }
+
+  $(document).ready(function() {
+    var select = build_select(DOCUMENTATION_OPTIONS.VERSION,
+                              DOCUMENTATION_OPTIONS.RELEASE);
+    $('.version_switcher_placeholder').html(select);
+    $('.version_switcher_placeholder select').bind('change', on_switch);
+  });
+})();
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -234,6 +234,9 @@
 Documentation
 -------------
 
+- Issue #8040: added a version switcher to the documentation.  Patch by
+  Yury Selivanov.
+
 - Additional comments and some style changes in the concurrent.futures URL
   retrieval example
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list