Don't collapse modindex if number of submodules is larger

than number of toplevel modules.
This commit is contained in:
Georg Brandl 2008-06-22 19:23:00 +00:00
parent 99f293acbd
commit 3a943ab25f
4 changed files with 25 additions and 4 deletions

View File

@ -501,6 +501,8 @@ class StandaloneHTMLBuilder(Builder):
modindexentries = [] modindexentries = []
letters = [] letters = []
pmn = '' pmn = ''
num_toplevels = 0
num_collapsables = 0
cg = 0 # collapse group cg = 0 # collapse group
fl = '' # first letter fl = '' # first letter
for mn, (fn, sy, pl, dep) in modules: for mn, (fn, sy, pl, dep) in modules:
@ -517,21 +519,29 @@ class StandaloneHTMLBuilder(Builder):
if pmn == tn: if pmn == tn:
# first submodule - make parent collapsable # first submodule - make parent collapsable
modindexentries[-1][1] = True modindexentries[-1][1] = True
num_collapsables += 1
elif not pmn.startswith(tn): elif not pmn.startswith(tn):
# submodule without parent in list, add dummy entry # submodule without parent in list, add dummy entry
cg += 1 cg += 1
modindexentries.append([tn, True, cg, False, '', '', [], False]) modindexentries.append([tn, True, cg, False, '', '', [], False])
else: else:
num_toplevels += 1
cg += 1 cg += 1
modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl, dep]) modindexentries.append([mn, False, cg, (tn != mn), fn, sy, pl, dep])
pmn = mn pmn = mn
fl = mn[0].lower() fl = mn[0].lower()
platforms = sorted(platforms) 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( modindexcontext = dict(
modindexentries = modindexentries, modindexentries = modindexentries,
platforms = platforms, platforms = platforms,
letters = letters, letters = letters,
collapse = collapse,
) )
self.info(' modindex', nonl=1) self.info(' modindex', nonl=1)
self.handle_page('modindex', modindexcontext, 'modindex.html') self.handle_page('modindex', modindexcontext, 'modindex.html')

View File

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

View File

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

View File

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