1. Luke Plant
  2. sphinx

Commits

georg.brandl  committed 14df265

Don't collapse modindex if number of submodules is larger
than number of toplevel modules.

  • Participants
  • Parent commits 4450e8e
  • Branches default

Comments (0)

Files changed (4)

File sphinx/builder.py

View file
             modindexentries = []
             letters = []
             pmn = ''
+            num_toplevels = 0
+            num_collapsables = 0
             cg = 0 # collapse group
             fl = '' # first letter
             for mn, (fn, sy, pl, dep) in modules:
                     if pmn == tn:
                         # first submodule - make parent collapsable
                         modindexentries[-1][1] = True
+                        num_collapsables += 1
                     elif not pmn.startswith(tn):
                         # submodule without parent in list, add dummy entry
                         cg += 1
                         modindexentries.append([tn, True, cg, False, '', '', [], False])
                 else:
+                    num_toplevels += 1
                     cg += 1
                 modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl, dep])
                 pmn = mn
                 fl = mn[0].lower()
             platforms = sorted(platforms)
 
+            # apply heuristics when to collapse modindex at page load:
+            # only collapse if number of toplevel modules is larger than
+            # number of submodules
+            collapse = len(modules) - num_toplevels > num_toplevels
+
             modindexcontext = dict(
                 modindexentries = modindexentries,
                 platforms = platforms,
                 letters = letters,
+                collapse = collapse,
             )
             self.info(' modindex', nonl=1)
             self.handle_page('modindex', modindexcontext, 'modindex.html')

File sphinx/static/doctools.js

View file
    * init the modindex toggle buttons
    */
   initModIndex : function() {
-    $('img.toggler').click(function() {
+    var togglers = $('img.toggler').click(function() {
       var src = $(this).attr('src');
       var idnum = $(this).attr('id').substr(7);
       console.log($('tr.cg-' + idnum).toggle());
         $(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
       else
         $(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
-    }).css('display', '').click();
+    }).css('display', '');
+    if (DOCUMENTATION_OPTIONS.COLLAPSE_MODINDEX) {
+        togglers.click();
+    }
   },
 
   /**

File sphinx/templates/layout.html

View file
     {%- if builder != 'htmlhelp' %}
     <script type="text/javascript">
       var DOCUMENTATION_OPTIONS = {
-        URL_ROOT:   '{{ pathto("", 1) }}',
-        VERSION:    '{{ release }}'
+          URL_ROOT:   '{{ pathto("", 1) }}',
+          VERSION:    '{{ release }}',
+          COLLAPSE_MODINDEX: false,
       };
     </script>
     <script type="text/javascript" src="{{ pathto('_static/jquery.js', 1) }}"></script>

File sphinx/templates/modindex.html

View file
 {% extends "layout.html" %}
 {% set title = 'Global Module Index' %}
+{% block extrahead %}
+{% if collapse_modindex %}
+    <script type="text/javascript">
+      DOCUMENTATION_OPTIONS.COLLAPSE_MODINDEX = true;
+    </script>
+{% endif %}
+{% endblock %}
 {% block body %}
 
    <h1 id="global-module-index">Global Module Index</h1>