Attachment 'CollapsibleSection.py'
Download 1 """
2 MoinMoin - Collapsible Section macro
3
4 This macro provides a way to display the contents of another page into
5 an HTML div that can be collapsed and expanded. Its useful for including
6 supplemental information in a page that normal users might not care about.
7
8 Example Usage:
9 collapsed by default:
10 <<CollapsibleSection("Title for Section", "PageName")>>
11 expanded by default
12 <<CollapsibleSection("Title for Section", "PageName", 1)>>
13
14 @license: GNU GPL, see COPYING for details.
15 """
16
17 from MoinMoin import wikiutil
18 from MoinMoin.macro import Include
19
20 section_js = """
21 <style type="text/css">
22 h2.CollapsibleSection{cursor: pointer;}
23 </style>
24 <script type='text/javascript'>
25 function toggle_viz(id) {
26 div = document.getElementById(id);
27 h2 = document.getElementById('h2_'+id);
28 if (div.style.display == 'none' ) {
29 div.style.display = 'block';
30 //strip the "> " from the old text
31 old = h2.innerHTML.substring(4);
32 h2.innerHTML = "^ " + old;
33 }
34 else {
35 div.style.display = 'none';
36 //strip the "^ " from the old text
37 old = h2.innerHTML.substring(2)
38 h2.innerHTML = "> " + old;
39 }
40 }
41 </script>
42 """
43 section_template = """
44 <h2 class='CollapsibleSection' id='h2_%s' onclick='toggle_viz("%s")'>%s</h2>
45 <div id='%s'>
46 %s
47 </div>
48 """
49
50 section_hide_template = """
51 <script type='text/javascript'>
52 toggle_viz('%s');
53 </script>
54 """
55
56 section_base = 'CollapsibleSection'
57
58 def macro_CollapsibleSection(macro, title, page, visible=False):
59 request = macro.request
60 idx = request.uid_generator(section_base)
61 html = ''
62 if idx == section_base:
63 #this is the first call to this macro, include the main JS code
64 html = section_js
65
66 title = "^ %s" % title
67 page_html = Include.execute(macro, page)
68 html += section_template % (idx, idx, title, idx, page_html)
69 if not visible:
70 hide_html = section_hide_template % idx
71 html += hide_html
72 return macro.formatter.rawHTML(html)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.