webmcp

changeset 390:ed910089a0c5

Keep track of expanded sections in autodoc reference (and collapse sections on hash change)
author jbe
date Thu Dec 03 18:26:49 2015 +0100 (2015-12-03)
parents a7a335e2db93
children a932b94a8490
files doc/autodoc-header.htmlpart framework/bin/autodoc.lua
line diff
     1.1 --- a/doc/autodoc-header.htmlpart	Thu Dec 03 02:32:20 2015 +0100
     1.2 +++ b/doc/autodoc-header.htmlpart	Thu Dec 03 18:26:49 2015 +0100
     1.3 @@ -1,22 +1,25 @@
     1.4  <html>
     1.5    <head>
     1.6      <script type="text/javascript">
     1.7 -      var openedSection = null;
     1.8 -      var setSectionDisplay = function(disp) {
     1.9 -        var element = document.getElementById('autodoc_details_' + openedSection);
    1.10 -        if (element) element.style.display = disp;
    1.11 -      };
    1.12 -      var showSection = function() {
    1.13 -        openedSection = window.location.hash;
    1.14 -        if (openedSection) {
    1.15 -          openedSection = openedSection.replace(/^#/, '').replace(/_/g, '_USC_').replace(/\./g, '_DOT_').replace(/:/g, '_COL_');
    1.16 -          setSectionDisplay('');
    1.17 +      var expandedSections = {};
    1.18 +      function toggleSection(ident) {
    1.19 +        var element = document.getElementById('autodoc_details_' + ident);
    1.20 +        if (element) {
    1.21 +          if (expandedSections[ident]) {
    1.22 +            element.style.display = 'none';
    1.23 +            delete expandedSections[ident];
    1.24 +          } else {
    1.25 +            element.style.display = '';
    1.26 +            expandedSections[ident] = true;
    1.27 +          }
    1.28          }
    1.29 -      };
    1.30 -      window.onload = showSection;
    1.31 -      window.onhashchange = function() {
    1.32 -        setSectionDisplay('none');
    1.33 -        showSection();
    1.34 +      }
    1.35 +      window.onload = window.onhashchange = function() {
    1.36 +        for (var ident in expandedSections) toggleSection(ident);
    1.37 +        var hash = window.location.hash;
    1.38 +        if (hash) {
    1.39 +          toggleSection(hash.replace(/^#/, ''));
    1.40 +        }
    1.41        };
    1.42      </script>
    1.43      <style>
     2.1 --- a/framework/bin/autodoc.lua	Thu Dec 03 02:32:20 2015 +0100
     2.2 +++ b/framework/bin/autodoc.lua	Thu Dec 03 18:26:49 2015 +0100
     2.3 @@ -183,28 +183,15 @@
     2.4    local entry = entries[key]
     2.5    local m1, m2 = string.match(key, "<?([A-Za-z0-9_]*)>?([A-Za-z0-9_.:]+)")
     2.6    local anchor = m1 .. m2
     2.7 -  local ident = anchor:gsub("_", "_USC_"):gsub("%.", "_DOT_"):gsub(":", "_COL_")
     2.8 -  output('<a name="', anchor, '">')
     2.9 -  output('  <li class="autodoc_entry">\n')
    2.10 -  output(
    2.11 -    '    <div class="short_synopsis" onclick="window.onhashchange = null;',
    2.12 -    ' document.getElementById(\'autodoc_details_',
    2.13 -    ident,
    2.14 -    '\').style.display = document.getElementById(\'autodoc_details_',
    2.15 -    ident,
    2.16 -    '\').style.display ? \'\' : \'none\';">\n'
    2.17 -  )
    2.18 -  output('      ', encode(entry.func_call), '\n')
    2.19 +  output('<li id="', anchor, '" class="autodoc_entry">\n')
    2.20 +  output('  <div class="short_synopsis" onclick="toggleSection(\'', anchor, '\')">\n')
    2.21 +  output('    ', encode(entry.func_call), '\n')
    2.22 +  output('  </div>\n')
    2.23 +  output('  <div id="autodoc_details_', anchor, '" class="autodoc_details" style="display: none;">\n')
    2.24 +  output('    <div class="autodoc_synopsis">\n')
    2.25 +  output_lines(entry.synopsis)
    2.26    output('    </div>\n')
    2.27 -  output(
    2.28 -    '    <div id="autodoc_details_',
    2.29 -    ident,
    2.30 -    '" class="autodoc_details" style="display: none;">\n'
    2.31 -  )
    2.32 -  output('      <div class="autodoc_synopsis">\n')
    2.33 -  output_lines(entry.synopsis)
    2.34 -  output('      </div>\n')
    2.35 -  output('      <div class="autodoc_comment">')
    2.36 +  output('    <div class="autodoc_comment">')
    2.37    for idx, line in ipairs(entry.comment) do
    2.38      output(encode(line))
    2.39      if idx < #entry.comment then
    2.40 @@ -212,10 +199,9 @@
    2.41      end
    2.42    end
    2.43    output('</div>\n')
    2.44 -  output('      <div class="autodoc_source">\n')
    2.45 +  output('    <div class="autodoc_source">\n')
    2.46    output_lines(entry.source)
    2.47 -  output('      </div>\n')
    2.48    output('    </div>\n')
    2.49 -  output('  </li>\n')
    2.50 -  output('</a>')
    2.51 +  output('  </div>\n')
    2.52 +  output('</li>\n')
    2.53  end

Impressum / About Us