source: trunk/TwistyPlugin/data/System/TwistyPlugin.txt @ 8646

Revision 8646, 14.7 KB checked in by SvenDowideit, 3 years ago (diff)

Item9383: add one Var topic per MACRO, so that any user looking up a macro by name will find it.

Line 
1%META:TOPICINFO{author="ProjectContributor" date="1195487956" format="1.1" version="$Rev$"}%
2%META:TOPICPARENT{name="Plugins"}%
3---+!! <nop>%TOPIC%
4
5*A "twisty" is an interface toggle control to show and hide content.*
6
7!TwistyPlugin gives you several options to control the appearance of a twisty:
8   * use link text or buttons
9   * position an icon left or right
10   * remember the state at the next visit of the page
11   * start the Twisty open or closed
12   * start the Twisty open or closed for the first visit
13   * use a span or div for the content
14   * set a class for the content span or div
15
16Twisty has a fallback mechanism in case !JavaScript is not available: all content is displayed and the control buttons are hidden.
17
18%TOC{title="On this page:"}%
19
20---++ Usage examples
21---+++ Triad
22A Twisty consists of 3 elements:
23   1 Show button
24   1 Hide button
25   1 Collapsing content ('Toggle')
26   
27The typical !TwistyPlugin triad will look like this (pseudo code):
28
29<verbatim class="tml">
30%TWISTYSHOW{}% %TWISTYHIDE{}%
31(there may be other things between buttons and content)
32%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%
33</verbatim>
34
35---+++ Shorthand
36
37The Twisty triad is conveniently packed into shorthand =%<nop>TWISTY{some parameters}% Collapsing content %<nop>ENDTWISTY%=:
38
39<verbatim class="tml">
40%TWISTY{}%
41my twisty content
42%ENDTWISTY%
43</verbatim>
44
45Will generate:
46
47%TWISTY{}%
48%GREEN% my twisty content %ENDCOLOR%
49%ENDTWISTY%
50
51You may have noticed that no parameters are passed to =%<nop>TWISTY{}%= but the show and hide links _do_ have text! The default values are fetched from plugin settings =TWISTYSHOWLINK= and =TWISTYHIDELINK=, see [[#PluginSettings][Plugin Settings]] below.
52
53
54---+++ Twisty with icons
55We will use =mode="div"= to put the collapsing content below the button (the default mode is ="span"=).
56
57<verbatim class="tml">
58%TWISTY{
59    mode="div"
60    showlink="Show..."
61    hidelink="Hide"
62    showimgleft="%ICONURLPATH{toggleopen-small}%"
63    hideimgleft="%ICONURLPATH{toggleclose-small}%"
64}%
65my twisty content
66%ENDTWISTY%
67</verbatim>
68
69It will look like this:
70
71%TWISTY{
72mode="div"
73showlink="Show..."
74hidelink="Hide"
75showimgleft="%ICONURLPATH{toggleopen-small}%"
76hideimgleft="%ICONURLPATH{toggleclose-small}%"
77}%
78%GREEN% my twisty content %ENDCOLOR%
79%ENDTWISTY%
80
81To put icons at the right side, write
82<verbatim class="tml">
83%TWISTY{
84    mode="div"
85    showlink="Show&nbsp;"
86    hidelink="Hide&nbsp;"
87    showimgright="%ICONURLPATH{toggleopen-small}%"
88    hideimgright="%ICONURLPATH{toggleclose-small}%"
89}%
90my twisty content
91%ENDTWISTY%
92</verbatim>
93
94%TWISTY{
95mode="div"
96showlink="Show&nbsp;"
97hidelink="Hide&nbsp;"
98showimgright="%ICONURLPATH{toggleopen-small}%"
99hideimgright="%ICONURLPATH{toggleclose-small}%"
100}%
101%GREEN% my twisty content %ENDCOLOR%
102%ENDTWISTY%
103
104
105
106---+++ Make it remember
107To store the last state in a FOSWIKIPREF cookie, add the parameter =remember="on"=.%BR%
108To test this, reload the page after toggling.
109
110<verbatim class="tml">
111%TWISTY{
112    showlink="Show..."
113    hidelink="Hide"
114    remember="on"
115}%
116my twisty content
117%ENDTWISTY%
118</verbatim>
119
120%TWISTY{
121showlink="Show..."
122hidelink="Hide"
123remember="on"
124}%
125%GREEN% my twisty content %ENDCOLOR%
126%ENDTWISTY%
127
128If a Twisty state has been stored in a FOSWIKIPREF cookie before, it can be cleared by using =remember="off"=:
129
130<verbatim class="tml">
131%TWISTY{
132    showlink="Show..."
133    hidelink="Hide"
134    remember="off"
135}%
136my twisty content
137%ENDTWISTY%
138</verbatim>
139
140%TWISTY{
141    showlink="Show..."
142    hidelink="Hide"
143    remember="off"
144}%
145%GREEN% my twisty content %ENDCOLOR%
146%ENDTWISTY%
147
148*NOTE:* Twisty ids are generated automatically. If you need control over exactly _which_ Twisty should be remembered, add the parameter =id=:
149
150<verbatim class="tml">
151%TWISTY{
152    id="currentCustomerList"
153    showlink="Show..."
154    hidelink="Hide"
155    remember="on"
156}%
157my customer list
158%ENDTWISTY%
159</verbatim>
160
161Note that =id= sets a sitewide cookie. To create a unique id, add topic or web macros:
162<verbatim class="tml">
163id="%WEB%_%TOPIC%_currentCustomerList"
164</verbatim>
165
166
167
168---+++ Make it obey
169To let the Twisty start with its content folded open, add parameter =start="show"=.
170
171<verbatim class="tml">
172%TWISTY{
173    showlink="Show..."
174    hidelink="Hide"
175    start="show"
176}%
177my twisty content
178%ENDTWISTY%
179</verbatim>
180
181%TWISTY{
182    showlink="Show..."
183    hidelink="Hide"
184    start="show"
185}%
186%GREEN% my twisty content %ENDCOLOR%
187%ENDTWISTY%
188
189Likewise use =start="hide"= to start with hidden content.
190
191<verbatim class="tml">
192%TWISTY{
193    showlink="Show..."
194    hidelink="Hide"
195    start="hide"
196}%
197my twisty content
198%ENDTWISTY%
199</verbatim>
200
201%TWISTY{
202    showlink="Show..."
203    hidelink="Hide"
204    start="hide"
205}%
206%GREEN% my twisty content %ENDCOLOR%
207%ENDTWISTY%
208
209
210
211---+++ Make it obey only the first time
212To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter =firststart="show"=.
213If =remember="on"= is used, subsequential visits to the page will display the Twisty according the cookie setting.
214
215<verbatim class="tml">
216%TWISTY{
217    showlink="Show..."
218    hidelink="Hide"
219    firststart="show"
220}%
221my twisty content
222%ENDTWISTY%
223</verbatim>
224
225%TWISTY{
226    showlink="Show..."
227    hidelink="Hide"
228    firststart="show"
229}%
230%GREEN% my twisty content %ENDCOLOR%
231%ENDTWISTY%
232
233
234---+++ Other use: hide interface parts in case of no !JavaScript
235
236You can use Twisty to show interface elements that should only be visible with !JavaScript enabled. For instance the textbox control buttons in the edit screen need !JavaScript to work. If a visitor does not have !JavaScript on it would not make sense to show these buttons.
237
238Put the "JavaScript content" in an almost bare bones Twisty. Write =showlink="" hidelink=""= to not display any default link texts.
239
240<verbatim class="tml">
241%TWISTY{
242    link=""
243    noscript="hide"
244    start="show"
245}%
246<input type="submit" class="foswikiButton" value="You surely have !JavaScript" />
247%ENDTWISTY%
248</verbatim>
249
250%TWISTY{
251    link=""
252    noscript="hide"
253    start="show"
254}%
255<input type="submit" class="foswikiButton" value="You surely have !JavaScript" />
256%ENDTWISTY%
257
258Do not forget to set =start="show"= to show the Twisty content at all.
259
260When !JavaScript is off, the button should be invisible.
261
262This code will show the button when !JavaScript is off:
263
264<verbatim class="tml">
265%TWISTY{
266    link=""
267    start="show"
268}%
269<input type="submit" class="foswikiButton" value="You might have !JavaScript" />
270%ENDTWISTY%
271</verbatim>
272
273%TWISTY{
274    link=""
275    start="show"
276}%
277<input type="submit" class="foswikiButton" value="You might have !JavaScript" />
278%ENDTWISTY%
279
280
281
282---+++ Styling the Twisty
283Use parameter =class= to style the content div or class:
284
285<verbatim class="tml">
286%TWISTY{
287    mode="div"
288    showlink="Show..."
289    hidelink="Hide"
290    class="foswikiHelp"
291}%
292my twisty content
293%ENDTWISTY%
294</verbatim>
295
296Generates: %BR%
297%TWISTY{
298    mode="div"
299    showlink="Show..."
300    hidelink="Hide"
301    class="foswikiHelp"
302}%
303%GREEN% my twisty content %ENDCOLOR%
304%ENDTWISTY%
305
306
307---+++ Styling the Twisty link or button
308Use parameter =linkclass= to style the twisty links:
309
310<verbatim class="tml">
311%TWISTY{
312    mode="div"
313    showlink="Show..."
314    hidelink="Hide"
315    linkclass="foswikiButton"
316}%
317my twisty content
318%ENDTWISTY%
319</verbatim>
320
321Generates: %BR%
322%TWISTY{
323mode="div"
324showlink="Show..."
325hidelink="Hide"
326linkclass="foswikiButton"
327}%
328%GREEN% my twisty content %ENDCOLOR%
329%ENDTWISTY%
330
331
332---+++ Twisty headers
333To be able to use header tags like =&lt;h2&lt;=, use the properties =prefix= and =suffix=. Because we have identical show and hide links we can use the shorthand property =link=.
334
335<verbatim class="tml">
336%TWISTY{
337    prefix="<h4>"
338    mode="div"
339    link="Twisty Header"
340    showimgleft="%ICONURLPATH{toggleopen}%"
341    hideimgleft="%ICONURLPATH{toggleclose}%"
342    suffix="</h4>"
343}%
344%GREEN% my twisty content %ENDCOLOR%
345%ENDTWISTY%
346</verbatim>
347
348Will create:
349
350%TWISTY{
351    prefix="<h4>"
352    mode="div"
353    link="Twisty Header"
354    showimgleft="%ICONURLPATH{toggleopen}%"
355    hideimgleft="%ICONURLPATH{toggleclose}%"
356    suffix="</h4>"
357}%
358%GREEN% my twisty content %ENDCOLOR%
359%ENDTWISTY%
360
361If you don't use images, there is an easier way to create a twisty header:
362
363<verbatim class="tml">
364%TWISTY{
365    mode="div"
366    showlink="<h4>&#9658; Details</h4>"
367    hidelink="<h4>&#9660; Details</h4>"
368}%
369%GREEN% my twisty content %ENDCOLOR%
370%ENDTWISTY%
371</verbatim>
372
373Will create:
374
375%TWISTY{
376    mode="div"
377    showlink="<h4>&#9658; Details</h4>"
378    hidelink="<h4>&#9660; Details</h4>"
379}%
380%GREEN% my twisty content %ENDCOLOR%
381%ENDTWISTY%
382
383---+++ All on, all off
384
385You can toggle all Twisties on or off at once by putting a link or button on the page with class =twistyExpandAll= or =twistyCollapseAll=.
386
387<verbatim class="tml">
388<button class="twistyExpandAll foswikiButton">Expand all</button>
389<button class="twistyCollapseAll foswikiButton">Collapse all</button>
390</verbatim>
391
392Creates these controls:
393
394<button class="twistyExpandAll foswikiButton">Expand all</button> &nbsp;
395<button class="twistyCollapseAll foswikiButton">Collapse all</button>
396
397When you want to use links, write:
398
399<verbatim class="tml">
400#VarTOGGLE
401
402<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp;
403<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>
404</verbatim>
405
406
407#VarTOGGLE
408
409<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp;
410<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>
411
412
413---++ Special syntax: format tokens
414If you use other macros inside TWISTY parameters chances are it will mess up the macro, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.
415
416The format tokens are the same as with %SYSTEMWEB%.FormattedSearch:
417
418| *Escape:* | *Expands To:* |
419| =$n= or =$n()= | New line. Use =$n()= if followed by alphanumeric character, e.g. write =Foo$n()Bar= instead of =Foo$nBar= |
420| =$nop= or =$nop()= | Is a "no operation". |
421| =$quot= | Double quote (="=) |
422| =$percent= | Percent sign (=%=) |
423| =$dollar= | Dollar sign (=$=) |
424
425
426For example, to show an icon inside the link, do not write:
427<verbatim class="tml">
428link="%Y%"
429</verbatim>
430
431but use format tokens:
432
433<verbatim class="tml">
434link="$percentY$percent"
435</verbatim>
436
437... to get:
438
439%TWISTY{
440mode="div"
441link="$percentY$percent"
442showimgleft="%ICONURLPATH{toggleopen-small}%"
443hideimgleft="%ICONURLPATH{toggleclose-small}%"
444}%
445my twisty content
446%ENDTWISTY%
447
448Or a more complex example using %SYSTEMWEB%.SpreadSheetPlugin; do not write:
449
450<verbatim class="tml">
451link="Count: (%CALC{"$GET(infoCount)"}%)"
452</verbatim>
453
454but use format tokens:
455
456<verbatim class="tml">
457link="Count: ($percentCALC{$quot$dollarGET(infoCount)$quot}$percent)"
458</verbatim>
459
460
461---++ Syntax
462%INCLUDE{VarTWISTY}%
463%INCLUDE{VarENDTWISTYTOGGLE}%
464%INCLUDE{VarENDTWISTY}%
465%INCLUDE{VarTWISTYBUTTON}%
466%INCLUDE{VarTWISTYHIDE}%
467%INCLUDE{VarTWISTYSHOW}%
468%INCLUDE{VarTWISTYTOGGLE}%
469
470
471#PluginSettings
472---++ Plugin Settings
473
474You can override some default settings in the plugin by setting the following [[%SYSTEMWEB%.PreferenceSettings][preferences]].
475| *Preference* | *Meaning* | *Default* |
476| =TWISTYSHOWLINK= | For example: =More...= | %MAKETEXT{"More..."}% |
477| =TWISTYHIDELINK= | For example: =Close= | %MAKETEXT{"Close"}% |
478| =TWISTYMODE= | Either =div= or =span= | =span= |
479| =TWISTYREMEMBER= | Either =on= or =off=. If set to =on= all Twisty states will be stored in a FOSWIKIPREF cookie; if set to =off= the FOSWIKIPREF cookie will be cleared | not specified |
480| =TWISTYANIMATIONSPEED= | Speed of animation: 'fast', 'slow', or integer milliseconds | =0= (no animation) |
481
482<!--
483   * Set SHORTDESCRIPTION = %$SHORTDESCRIPTION%
484-->
485   
486---++ Plugin Installation Instructions
487%$INSTALL_INSTRUCTIONS%
488
489---++ Plugin Info
490
491|  Authors: | Foswiki:Main.RafaelAlvarez, Foswiki:Main.MichaelDaum, Foswiki:Main.ArthurClemens |
492|  Copyright  | Copyright (C) Rafael Alvarez; Michael Daum, Arthur Clemens |
493|  License: | [[http://www.gnu.org/copyleft/gpl.html][GPL]] |
494|  Version: | %$VERSION% |
495|  Release: | %$RELEASE% |
496|  Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; |
497|  20 Aug 2010 | 1.6.1 Foswikitask:Item9499: Added preference variable to set show/hide transition animation speed (default to none) |
498|  15 Aug 2010 | 1.6.0<br/>\
499 Foswikitask:Item9422: Implement as JQueryPlugin::Plugin; emit =display: none= style on hidden twisties to avoid relying on CSS/JS<br/>\
500 Foswikitask:Item9415: Documentation changes<br/> |
501|  27 Jul 2010 | 1.5.6 Foswiki:Tasks.Item9387: Fixed jQuery JS |
502|  13 Mar 2010 | 1.5.5 Fixed id generated in subwebs. |
503|  12 Feb 2010 | 1.5.4 Fixed jquery twisties, improved templates structure |
504|  02 Sep 2009 | 1.5.3 Add sequential number to the =TWISTY= =id= to allow more than one instance with that id on the page. |
505|  26 Aug 2009 | 1.5.2 Fix dependencies - jqueryPlugin and DojoToolkit were ported to foswiki a while ago. |
506|  03 Dec 2008 | 1.5.1 Added parameter =linkclass=. Foswiki version. |
507|  27 Nov 2008 | 1.5 Foswiki release; added option to use other Javascript libraries. |
508|  08 Oct 2008 | 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak. |
509|  03 Aug 2008 | 1.4.10 TWiki 4.2.1 release version. |
510|  13 Dec 2007 | 1.4.9 fix to the loading order of javascript files in head. |
511|  24 Nov 2007 | 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens. |
512|  07 Oct 2007 | 1.4.5 Arthur Clemens - Fix html tag with show/hide controls. |
513|  25 Sep 2007 | 1.4.4 Arthur Clemens - Fix rendering of headers when =prefix= is used. |
514|  11 Jul 2007 | 1.4.3 Arthur Clemens - Fix invalid html when =prefix= and =suffix= is used. |
515|  23 Jun 2007 | 1.4.2 Arthur Clemens - Fixed bugs with parameters =firststart= and =noscript= (since version 1.4). |
516|  20 Jun 2007 | 1.4 Arthur Clemens - Updated to work without ugly inserted javascript 'init' calls. This will change nothing to the functionality, but it will produce cleaner HTML, while at the same time the twisty is still set immediately (not at page onload) and graceful fallback in case of no javascript is maintained. |
517|  19 Jun 2006 | 1.3 Arthur Clemens - Updated with TWiki 4 !JavaScript files. |
518|  25 Oct 2006 | 1.2 New variables to set default values: =TWISTYSHOWLINK=, =TWISTYHIDELINK=, =TWISTYMODE=, =TWISTYREMEMBER=; property =id= is no longer required as this is automatically set (still recommended in some cases with =remember="on"=); property value =remember="off"= will clear a previously stored cookie; new properties =prefix= and =suffix=; !JavaScript to collapse or expand all Twisties on the page.  |
519|  27 Sep 2006 | 1.101 Fixes !JavaScript handling when !AllowInlineScript in configure is not set |
520|  11 Jun 2006 | 1.100 Added parameters =start=, =firststart=, =noscript= and =class=; complete !JavaScript rewrite for speed |
521|  12 Sep 2005 | 1.000 First Version |
522|  Dependencies: | None |
523|  Home: | http://foswiki.org/Extensions/%TOPIC% |
524|  Support: | http://foswiki.org/Support/%TOPIC% |
525<!-- %JQREQUIRE{"chili"}% -->
Note: See TracBrowser for help on using the repository browser.