diff options
| author | georg.brandl <devnull@localhost> | 2008-06-22 19:23:00 +0000 |
|---|---|---|
| committer | georg.brandl <devnull@localhost> | 2008-06-22 19:23:00 +0000 |
| commit | 446ab3ad8808432413b8ee026719c6fd703ed5d6 (patch) | |
| tree | 1202bed190db86b402568b0573de0c45e62b114d | |
| parent | 1ccdf4c5c0c53b6b95f98291355c81da592d9796 (diff) | |
| download | sphinx-446ab3ad8808432413b8ee026719c6fd703ed5d6.tar.gz | |
Don't collapse modindex if number of submodules is larger
than number of toplevel modules.
| -rw-r--r-- | sphinx/builder.py | 10 | ||||
| -rw-r--r-- | sphinx/static/doctools.js | 7 | ||||
| -rw-r--r-- | sphinx/templates/layout.html | 5 | ||||
| -rw-r--r-- | sphinx/templates/modindex.html | 7 |
4 files changed, 25 insertions, 4 deletions
diff --git a/sphinx/builder.py b/sphinx/builder.py index b712dc86..c2cd86a7 100644 --- a/sphinx/builder.py +++ b/sphinx/builder.py @@ -501,6 +501,8 @@ class StandaloneHTMLBuilder(Builder): modindexentries = [] letters = [] pmn = '' + num_toplevels = 0 + num_collapsables = 0 cg = 0 # collapse group fl = '' # first letter for mn, (fn, sy, pl, dep) in modules: @@ -517,21 +519,29 @@ class StandaloneHTMLBuilder(Builder): 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') diff --git a/sphinx/static/doctools.js b/sphinx/static/doctools.js index 02cb0fee..b9155846 100644 --- a/sphinx/static/doctools.js +++ b/sphinx/static/doctools.js @@ -154,7 +154,7 @@ var Documentation = { * 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()); @@ -162,7 +162,10 @@ var Documentation = { $(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(); + } }, /** diff --git a/sphinx/templates/layout.html b/sphinx/templates/layout.html index d5391efc..1b14eb34 100644 --- a/sphinx/templates/layout.html +++ b/sphinx/templates/layout.html @@ -102,8 +102,9 @@ {%- 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> diff --git a/sphinx/templates/modindex.html b/sphinx/templates/modindex.html index 1afc1650..d0a20852 100644 --- a/sphinx/templates/modindex.html +++ b/sphinx/templates/modindex.html @@ -1,5 +1,12 @@ {% 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> |
