Attachment 'SeeSaw-0.1.py'
Download 1 # -*- coding: utf-8 -*-
2 '''
3 MoinMoin 1.6 - SeeSaw Macro
4 @copyright: 2008 Jim Wight
5 @licence: GNU GPL, see COPYING for details
6
7 PURPOSE
8 SeeSaw enables sections of a page to be individually see-sawed
9 (toggled) between hidden and shown, typically from near their
10 locations.
11
12 DESCRIPTION
13 SeeSaw adds a link for see-sawing a named section of a page. It is
14 created by a call of the following form:
15
16 <<SeeSaw(section="section", toshow="toshow", tohide="tohide",
17 show=True|False, bg="background", inline="inline")>>
18
19 where
20 section gives the section a name;
21 it defaults to 'section'
22 toshow specifies the text to display for showing the section
23 it defaults to 'Show' (for block) and '»»' (for inline)
24 tohide specifies the text to display for hiding the section;
25 it defaults to 'Hide' (block) and '««' (inline)
26 if toshow is given, but not tohide, tohide is set to the
27 value of toshow
28 show specifies whether the section is to be shown initially;
29 it defaults to False
30 bg specifies the background colour to use for the section;
31 it defaults to None
32 inline specifies the text of an inline section;
33 it defaults to None, and non-presence implies the call
34 relates to a block section
35
36 The (leading) arguments can also be given positionally, in the
37 order of the keyword arguments above, e.g.
38
39 <<SeeSaw("section1", "See-Saw")>>
40 <<SeeSaw("section1", show=True)>>
41
42 Block sections require to be set up as follows:
43
44 {{{#!wiki seesaw/section
45 }}}
46
47 where the word 'section' after '/' matches the value "section" in
48 the corresponding SeeSaw call.
49
50 By default, block sections are hidden initially, but can be shown
51 by adding '/show' to the '{{{#!wiki' line. 'show' should be set to
52 True in the matching SeeSaw call if its 'tohide' and 'toshow'
53 arguments are different (so that the correct one can be shown
54 initially)
55
56 If a background colour is specified for a block section,
57 '/"section"-bg' needs to be added to the corresponding '{{{#!wiki'
58 line to have the colour applied to the section. If there are
59 multiple sections with the same name, it is sufficient to use 'bg'
60 in just one of the SeeSaw calls, with the first taking precedence
61 if multiple, but different, values are given.
62
63 The text of inline sections is embedded in SeeSaw calls. By
64 default, inline sections are hidden initially.
65
66 SeeSaw sections behave similarly to MoinMoin comments in that all
67 sections with the same name are toggled together. In fact, if the
68 section name contains 'comment', it can be toggled on and off by
69 the 'Comments' link in the edit bar as well as by its own link,
70 along with any others whose names contain 'comment'.
71
72 If '/comment' is added to a '{{{#!wiki' line, the section becomes
73 a highlighted MoinMoin comment. However, as the MoinMoin comments
74 mechanism doesn't know anything about SeeSaw sections, the text of
75 the link doesn't get toggled when 'Comments' is used, so it is
76 best if the same text is used for both "tohide" and "toshow" in
77 that situation to avoid them getting out of sync.
78
79 Implementation requires the following jQuery code:
80
81 function seeSaw(section) {
82 $("span.seesaw." + section).toggle().not(":hidden").css("display","inline");
83 $("div.seesaw." + section).toggle();
84 };
85
86 $(document).ready(function() {
87 $("div.seesaw,span.seesawinline").not(".show").hide();
88 $("input.seesaw:hidden").each(function() {
89 bg = $(this).attr("value").split(":");
90 $("div.seesaw." + bg[0]).css("background-color",bg[1]).removeClass(bg[0]);
91 });
92 });
93
94 jQuery will be required until (if ever) I can be bothered to
95 rewrite using pure JavaScript. It can be downloaded from
96 http://jquery.com/
97
98 One way to load the local code and jQuery would be to place them
99 in /moin_static16x/common/js as local.js and jquery.js, say, and to
100 add the following to the configuration variable html_head:
101
102 <script type="text/javascript" src="/moin_static16x/common/js/jquery.js"></script>
103 <script type="text/javascript" src="/moin_static16x/common/js/local.js"></script>
104
105 EXAMPLES
106
107 <<SeeSaw(section="example1")>> example 1
108 {{{#!wiki seesaw/example1
109 This text was hidden initially and the link shown was Show;
110 it should now be Hide
111 }}}
112
113 <<SeeSaw("example2", show=True)>> example 2
114 {{{#!wiki seesaw/example2/show
115 This text is displayed initially and the link shown is Hide
116 }}}
117
118 <<SeeSaw(section="example3")>> example 3
119 {{{#!wiki seesaw/example3/comment
120 This is a both a SeeSaw section and a MoinMoin comment.
121 It (and any other MoinMoin comments) can be toggled on and off via the link
122 above or by the Comments link in the edit bar, but note that if the Comments
123 link is used, the text in the link gets out of sync.
124 }}}
125
126 <<SeeSaw(section="comment1")>> example 4
127 {{{#!wiki seesaw/comment1
128 This section can be toggled on and off via the link above or by the
129 Comments link in the edit bar - but it is not subject to MoinMoin
130 comment highlighting.
131 }}}
132
133 <<SeeSaw(section="example5", toshow="See-Saw", show=True, bg='#FFFFDD')>>
134 example 5
135 {{{#!wiki seesaw/example5/show
136 This is part 1 of example 5; it is displayed initially.<<BR>>
137 It is hidden and part 2 displayed when See-Saw is clicked
138 }}}
139 {{{#!wiki seesaw/example5/example5-bg
140 This is part 2 of example 5; it has a different background colour and is
141 displayed when part 1 is hidden.<<BR>>
142 It is hidden and part 1 displayed again when See-Saw is clicked.
143 }}}
144
145 Example 6 contains some
146 <<SeeSaw(section="inline1", inline=" hidden", bg='#FFFFDD')>> text.
147
148 Example 7 demonstrates toggling a
149 <<SeeSaw(section="comment", show=True, inline="MoinMoin")>> comment (plus
150 any other MoinMoin comments)
151
152
153 AUTHOR
154 Jim Wight <j.k.wight@ncl.ac.uk>
155
156 HISTORY
157 [v0.1] 2008-05-01
158 Initial version
159
160 '''
161
162 Dependencies = []
163 def execute(macro, args):
164 from MoinMoin import wikiutil
165
166 parser = wikiutil.ParameterParser('%(section)s%(toshow)s%(tohide)s%(show)b%(bg)s%(inline)s')
167 (count,dict) = parser.parse_parameters(args)
168 (section,toshow,tohide,show,bg,inline) = dict['section'], dict['toshow'], dict['tohide'], dict['show'], dict['bg'], dict['inline']
169 if section is None:
170 section = 'section'
171 if tohide is None and toshow is None:
172 if inline is None:
173 toshow = 'Show'; tohide = 'Hide'
174 else:
175 toshow = u'»»'; tohide = u'««'
176 elif tohide is None and toshow is not None:
177 tohide = toshow
178 if show is None:
179 show = False
180 if show:
181 toshow,tohide = tohide,toshow
182
183 comment = bgstyle = divstyle = shown = ""
184 if inline is None:
185 if bg is not None:
186 divstyle = '''<input class="seesaw" type="hidden" value="%(section)s-bg:%(bg)s">''' % locals()
187 else:
188 if show:
189 shown = "show"
190 if section != "comment" and bg is not None:
191 bgstyle = '''style="background-color:%(bg)s"''' % locals()
192 comment = '''<span class="seesaw seesawinline %(section)s %(shown)s" %(bgstyle)s>%(inline)s</span>''' % locals()
193
194 html = '''<a href="#" onClick='seeSaw("%(section)s");return false;'>%(divstyle)s<span class="seesaw %(section)s" style="display:inline">%(toshow)s</span><span class="seesaw %(section)s" style="display:none">%(tohide)s</span></a>%(comment)s''' % locals()
195
196 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.