[Pythonjp-checkins] [py26.python-doc-ja] push by songofacandy - Add version_switcher. on 2012-11-26 07:00 GMT

Back to archive index

pytho****@googl***** pytho****@googl*****
2012年 11月 26日 (月) 16:00:20 JST


Revision: f828784c42bc
Branch:   default
Author:   "INADA Naoki  <songo****@gmail*****>
Date:     Sun Nov 25 23:00:02 2012
Log:      Add version_switcher.
http://code.google.com/p/python-doc-ja/source/detail?r=f828784c42bc&repo=py26

Added:
  /tools/sphinxext/static/version_switch.js
Modified:
  /tools/sphinxext/layout.html

=======================================
--- /dev/null
+++ /tools/sphinxext/static/version_switch.js	Sun Nov 25 23:00:02 2012
@@ -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 = ['<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 = /\.jp\/(\d|py3k|dev|((release\/)?\d\.\d[\w\d\.]*))\//,
+        new_url = url.replace(url_re, '.jp/' + new_version + '/');
+
+    if (new_url == url && !new_url.match(url_re)) {
+      // python 2 url without version?
+      new_url = url.replace(/\.jp\//, '.jp/' + 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.jp/' + 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);
+  });
+})();
=======================================
--- /tools/sphinxext/layout.html	Sat Dec  4 22:30:27 2010
+++ /tools/sphinxext/layout.html	Sun Nov 25 23:00:02 2012
@@ -2,12 +2,20 @@
  {% block rootrellink %}
          <li><img src="{{ pathto('_static/py.png', 1) }}" alt=""
                   style="vertical-align: middle; margin-top: -1px"/></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/_jp.js', 1)  
}}"></script>
+    {% if versionswitcher is defined and not embedded %}<script  
type="text/javascript" src="{{ pathto('_static/version_switch.js', 1)  
}}"></script>{% endif %}
      {% endif %}
  {{ super() }}
  {% endblock %}




Pythonjp-checkins メーリングリストの案内
Back to archive index