Home - this site is powered by TWiki(R)
TWiki  TwistyPlugin (1 vs. 12)

Welcome | Register | Changes | Topics | Index | Search | Go

 <<O>>  Difference Topic TwistyPlugin (12 - 2018-07-06 - TWikiContributor)
 

TwistyPlugin

<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Twisty section JavaScript library to open/close content dynamically

Introduction

The TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:

  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

ALERT! Attention: The default mode works for content that is a single paragraph. Use the div mode in all other cases:

%TWISTY{ mode="div" }%
   * Bullet
%ENDTWISTY%

Will generate:

<--/twistyPlugin twikiMakeVisibleInline-->
  • Bullet
<--/twistyPlugin-->

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
  mode="div"
  showlink="Show..."
  hidelink="Hide"
  showimgleft="%ICONURLPATH{toggleopen-small}%"
  hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
  mode="div"
  showlink="Show&nbsp;"
  hidelink="Hide&nbsp;"
  showimgright="%ICONURLPATH{toggleopen-small}%"
  hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
  id="currentCustomerList"
  showlink="Show..."
  hidelink="Hide"
  remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: Hide interface if no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
  link=""
  noscript="hide"
  start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
  link=""
  start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
  mode="div"
  showlink="Show..."
  hidelink="Hide"
  class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
  prefix="<h4>!!"
  mode="div"
  link="Header"
  showimgleft="%ICONURLPATH{toggleopen}%"
  hideimgleft="%ICONURLPATH{toggleclose}%"
  suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar.
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadSheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.

  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.

  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link

  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link

  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section

  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure

  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

<--/twistyPlugin twikiMakeVisibleInline-->

Plugin settings are stored as preferences settings. Do not change the settings here, they are here only for illustration purposes showing the default values. Define the settings in Main.TWikiPreferences. For example, to customize the TWISTYREMEMBER setting, add a * Set TWISTYPLUGIN_TWISTYREMEMBER = ... bullet in Main.TWikiPreferences.

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

<--/twistyPlugin-->

Plugin Installation Instructions

This plugin is pre-installed. TWiki administrators can upgrade the plugin as needed on the TWiki server.

<--/twistyPlugin twikiMakeVisibleInline-->

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

<--/twistyPlugin-->

Plugin Info

Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens, TWiki:Main.PeterThoeny
Changed:
<
<
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2015 Peter Thoeny;
© 2005-2015 TWiki:TWiki.TWikiContributor
>
>
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2018 Peter Thoeny;
© 2005-2018 TWiki:TWiki.TWikiContributor
 
License: GPL (GNU General Public License)
Dependencies: TwistyContrib (pre-installed)
Changed:
<
<
Plugin Version: 2015-04-28
>
>
Plugin Version: 2018-07-06
 
<--/twistyPlugin twikiMakeVisibleInline-->
Added:
>
>
2018-07-06: TWikibug:Item7841: Copyright update to 2018
2016-01-09: TWikibug:Item7708: Copyright update to 2016
 
2015-04-28: TWikibug:Item7648: Less intrusive Twisty link - no dotted underlines on Twisty images
2015-02-16: TWikibug:Item7604: Switch from GPL v2 to v3
2013-03-22: TWikibug:Item7154: Doc fixes
2013-02-16: TWikibug:Item7123: Use TWISTY in plugin settings, installation instructions and change history; change TWIKIWEB to SYSTEMWEB
2012-11-14: TWikibug:Item7020: Categorize TWiki Variable -- TWiki:Main.PeterThoeny
2011-07-10: TWikibug:Item6725: Change global package variables from "use vars" to "our"
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 Initial version
<--/twistyPlugin-->
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory


 <<O>>  Difference Topic TwistyPlugin (11 - 2015-04-28 - TWikiContributor)
 

TwistyPlugin

<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Changed:
<
<
>
>
Added:
>
>
 
Changed:
<
<
>
>
Added:
>
>
 Twisty section JavaScript library to open/close content dynamically

Introduction

The TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:

  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

ALERT! Attention: The default mode works for content that is a single paragraph. Use the div mode in all other cases:

%TWISTY{ mode="div" }%
   * Bullet
%ENDTWISTY%

Will generate:

<--/twistyPlugin twikiMakeVisibleInline-->
  • Bullet
<--/twistyPlugin-->

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
  mode="div"
  showlink="Show..."
  hidelink="Hide"
  showimgleft="%ICONURLPATH{toggleopen-small}%"
  hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
  mode="div"
  showlink="Show&nbsp;"
  hidelink="Hide&nbsp;"
  showimgright="%ICONURLPATH{toggleopen-small}%"
  hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
  id="currentCustomerList"
  showlink="Show..."
  hidelink="Hide"
  remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
  showlink="Show..."
  hidelink="Hide"
  firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: Hide interface if no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
  link=""
  noscript="hide"
  start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
  link=""
  start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
  mode="div"
  showlink="Show..."
  hidelink="Hide"
  class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
  prefix="<h4>!!"
  mode="div"
  link="Header"
  showimgleft="%ICONURLPATH{toggleopen}%"
  hideimgleft="%ICONURLPATH{toggleclose}%"
  suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar.
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadSheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.

  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.

  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link

  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link

  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section

  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure

  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

<--/twistyPlugin twikiMakeVisibleInline-->

Plugin settings are stored as preferences settings. Do not change the settings here, they are here only for illustration purposes showing the default values. Define the settings in Main.TWikiPreferences. For example, to customize the TWISTYREMEMBER setting, add a * Set TWISTYPLUGIN_TWISTYREMEMBER = ... bullet in Main.TWikiPreferences.

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

<--/twistyPlugin-->

Plugin Installation Instructions

This plugin is pre-installed. TWiki administrators can upgrade the plugin as needed on the TWiki server.

<--/twistyPlugin twikiMakeVisibleInline-->

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

<--/twistyPlugin-->

Plugin Info

Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens, TWiki:Main.PeterThoeny
Changed:
<
<
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2013 Peter Thoeny;
© 2005-2013 TWiki:TWiki.TWikiContributor
>
>
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2015 Peter Thoeny;
© 2005-2015 TWiki:TWiki.TWikiContributor
 
License: GPL (GNU General Public License)
Dependencies: TwistyContrib (pre-installed)
Changed:
<
<
Plugin Version: 2013-03-22
>
>
Plugin Version: 2015-04-28
 
<--/twistyPlugin twikiMakeVisibleInline-->
Added:
>
>
2015-04-28: TWikibug:Item7648: Less intrusive Twisty link - no dotted underlines on Twisty images
2015-02-16: TWikibug:Item7604: Switch from GPL v2 to v3
 
2013-03-22: TWikibug:Item7154: Doc fixes
2013-02-16: TWikibug:Item7123: Use TWISTY in plugin settings, installation instructions and change history; change TWIKIWEB to SYSTEMWEB
2012-11-14: TWikibug:Item7020: Categorize TWiki Variable -- TWiki:Main.PeterThoeny
2011-07-10: TWikibug:Item6725: Change global package variables from "use vars" to "our"
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 Initial version
<--/twistyPlugin-->
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory


 <<O>>  Difference Topic TwistyPlugin (10 - 2013-03-23 - TWikiContributor)
 

TwistyPlugin

<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Twisty section JavaScript library to open/close content dynamically

Introduction

The TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:

  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Added:
>
>
ALERT! Attention: The default mode works for content that is a single paragraph. Use the div mode in all other cases:
 
Added:
>
>
%TWISTY{ mode="div" }%
   * Bullet
%ENDTWISTY%

Will generate:

<--/twistyPlugin twikiMakeVisibleInline-->
  • Bullet
<--/twistyPlugin-->
 

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
Changed:
<
<
mode="div" showlink="Show..." hidelink="Hide" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
>
>
mode="div" showlink="Show..." hidelink="Hide" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
 }% my twisty content </>
<--/twistyPlugin-->

It will look like this:

%TWISTY{

Changed:
<
<
mode="div" showlink="Show..." hidelink="Hide" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
>
>
mode="div" showlink="Show..." hidelink="Hide" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
 }% my twisty content </>
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
Changed:
<
<
mode="div" showlink="Show " hidelink="Hide " showimgright="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgright="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
>
>
mode="div" showlink="Show " hidelink="Hide " showimgright="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgright="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
 }% my twisty content </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
mode="div" showlink="Show " hidelink="Hide " showimgright="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgright="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
>
>
mode="div" showlink="Show " hidelink="Hide " showimgright="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgright="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
 }% my twisty content </>
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
Changed:
<
<
showlink="Show..." hidelink="Hide" remember="on"
>
>
showlink="Show..." hidelink="Hide" remember="on"
 }% my twisty content </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
showlink="Show..." hidelink="Hide" remember="on"
>
>
showlink="Show..." hidelink="Hide" remember="on"
 }% my twisty content </>
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
Changed:
<
<
showlink="Show..." hidelink="Hide" remember="off"
>
>
showlink="Show..." hidelink="Hide" remember="off"
 }% my twisty content </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
showlink="Show..." hidelink="Hide" remember="off"
>
>
showlink="Show..." hidelink="Hide" remember="off"
 }% my twisty content </>
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
Changed:
<
<
id="currentCustomerList" showlink="Show..." hidelink="Hide" remember="on"
>
>
id="currentCustomerList" showlink="Show..." hidelink="Hide" remember="on"
 }% my customer list </>
<--/twistyPlugin-->

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
Changed:
<
<
showlink="Show..." hidelink="Hide" start="show"
>
>
showlink="Show..." hidelink="Hide" start="show"
 }% my twisty content </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
showlink="Show..." hidelink="Hide" start="show"
>
>
showlink="Show..." hidelink="Hide" start="show"
 }% my twisty content </>
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
Changed:
<
<
showlink="Show..." hidelink="Hide" start="hide"
>
>
showlink="Show..." hidelink="Hide" start="hide"
 }% my twisty content </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
showlink="Show..." hidelink="Hide" start="hide"
>
>
showlink="Show..." hidelink="Hide" start="hide"
 }% my twisty content </>
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
Changed:
<
<
showlink="Show..." hidelink="Hide" firststart="show"
>
>
showlink="Show..." hidelink="Hide" firststart="show"
 }% my twisty content </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
showlink="Show..." hidelink="Hide" firststart="show"
>
>
showlink="Show..." hidelink="Hide" firststart="show"
 }% my twisty content </>
<--/twistyPlugin-->

Other use: Hide interface if no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
Changed:
<
<
link="" noscript="hide" start="show"
>
>
link="" noscript="hide" start="show"
 }% </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
link="" noscript="hide" start="show"
>
>
link="" noscript="hide" start="show"
 }% </>
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
Changed:
<
<
link="" start="show"
>
>
link="" start="show"
 }% </>
<--/twistyPlugin-->

%TWISTY{

Changed:
<
<
link="" start="show"
>
>
link="" start="show"
 }% </>
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
Changed:
<
<
mode="div" showlink="Show..." hidelink="Hide" class="twikiHelp"
>
>
mode="div" showlink="Show..." hidelink="Hide" class="twikiHelp"
 }% my twisty content </>
<--/twistyPlugin-->

Generates:
%TWISTY{

Changed:
<
<
mode="div" showlink="Show..." hidelink="Hide" class="twikiHelp"
>
>
mode="div" showlink="Show..." hidelink="Hide" class="twikiHelp"
 }% my twisty content </>
<--/twistyPlugin-->

Twisty headers

Changed:
<
<
To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.
>
>
To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.
 
%TWISTY{
Changed:
<
<
prefix="

!!" mode="div" link="Header" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix="

"
>
>
prefix="

!!" mode="div" link="Header" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix="

"
 }% my twisty content </>
<--/twistyPlugin-->

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

%TWISTY{

Changed:
<
<
prefix="

!!" mode="div" link="Header" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix="

"
>
>
prefix="

!!" mode="div" link="Header" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix="

"
 }% my twisty content </>
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
Changed:
<
<
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
>
>
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar.
 
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

%TWISTY{

Changed:
<
<
mode="div" link="$percntY$percnt" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
>
>
mode="div" link="$percntY$percnt" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"
 }% my twisty content </>
<--/twistyPlugin-->

Or a more complex example using SpreadSheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.

  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.

  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link

  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link

  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section

  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure

  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

<--/twistyPlugin twikiMakeVisibleInline-->

Plugin settings are stored as preferences settings. Do not change the settings here, they are here only for illustration purposes showing the default values. Define the settings in Main.TWikiPreferences. For example, to customize the TWISTYREMEMBER setting, add a * Set TWISTYPLUGIN_TWISTYREMEMBER = ... bullet in Main.TWikiPreferences.

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

<--/twistyPlugin-->

Plugin Installation Instructions

This plugin is pre-installed. TWiki administrators can upgrade the plugin as needed on the TWiki server.

<--/twistyPlugin twikiMakeVisibleInline-->

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
Deleted:
<
<
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
 
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

<--/twistyPlugin-->

Plugin Info

Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens, TWiki:Main.PeterThoeny
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2013 Peter Thoeny;
© 2005-2013 TWiki:TWiki.TWikiContributor
License: GPL (GNU General Public License)
Dependencies: TwistyContrib (pre-installed)
Changed:
<
<
Plugin Version: 2013-02-16
>
>
Plugin Version: 2013-03-22
 
<--/twistyPlugin twikiMakeVisibleInline-->
Added:
>
>
2013-03-22: TWikibug:Item7154: Doc fixes
 
2013-02-16: TWikibug:Item7123: Use TWISTY in plugin settings, installation instructions and change history; change TWIKIWEB to SYSTEMWEB
2012-11-14: TWikibug:Item7020: Categorize TWiki Variable -- TWiki:Main.PeterThoeny
2011-07-10: TWikibug:Item6725: Change global package variables from "use vars" to "our"
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 Initial version
<--/twistyPlugin-->
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory


 <<O>>  Difference Topic TwistyPlugin (9 - 2013-02-16 - TWikiContributor)
 

TwistyPlugin

<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Twisty section JavaScript library to open/close content dynamically

Introduction

The TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:

  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
mode="div"
showlink="Show&nbsp;"
hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%"
hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
id="currentCustomerList"
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
showlink="Show..."
hidelink="Hide"
firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: Hide interface if no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
link=""
noscript="hide"
start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
link=""
start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
prefix="<h4>!!"
mode="div"
link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%"
suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadSheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.

  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.

  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link

  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link

  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section

  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    <-- -->
    Sorted ascending
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    class CSS class name Class for content div or span optional, default none
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure

  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Changed:
<
<
Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%
>
>
%TWISTY{
Added:
>
>
mode="div" showlink="Show details toggleopen.gif " hidelink="Hide details toggleclose.gif " }%
 
Added:
>
>
Plugin settings are stored as preferences settings. Do not change the settings here, they are here only for illustration purposes showing the default values. Define the settings in Main.TWikiPreferences. For example, to customize the TWISTYREMEMBER setting, add a * Set TWISTYPLUGIN_TWISTYREMEMBER = ... bullet in Main.TWikiPreferences.
 
  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0
Added:
>
>
</>
<--/twistyPlugin-->
 

Plugin Installation Instructions

Added:
>
>
This plugin is pre-installed. TWiki administrators can upgrade the plugin as needed on the TWiki server.
<--/twistyPlugin twikiMakeVisibleInline-->
 
  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.
Added:
>
>
<--/twistyPlugin-->
 

Plugin Info

Added:
>
>
 
Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens, TWiki:Main.PeterThoeny
Changed:
<
<
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2012 Peter Thoeny;
© 2005-2012 TWiki:TWiki.TWikiContributor
>
>
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2013 Peter Thoeny;
© 2005-2013 TWiki:TWiki.TWikiContributor
 
License: GPL (GNU General Public License)
Changed:
<
<
Dependencies: None
Plugin Version: 2012-11-14
Change History:
<-- versions below in reverse order -->
 
>
>
Dependencies: TwistyContrib (pre-installed)
Plugin Version: 2013-02-16
%TWISTY{
Added:
>
>
mode="div" showlink="Show Change History http://tait.tcyrus.com/pub/TWiki/TWikiDocGraphics/toggleopen.gif" hidelink="Hide Change History http://tait.tcyrus.com/pub/TWiki/TWikiDocGraphics/toggleclose.gif" }%
2013-02-16: TWikibug:Item7123: Use TWISTY in plugin settings, installation instructions and change history; change TWIKIWEB to SYSTEMWEB
 
2012-11-14: TWikibug:Item7020: Categorize TWiki Variable -- TWiki:Main.PeterThoeny
2011-07-10: TWikibug:Item6725: Change global package variables from "use vars" to "our"
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
Changed:
<
<
12 Sep 2005 1.000 First Version
>
>
12 Sep 2005 1.000 Initial version
Added:
>
>
</>
<--/twistyPlugin-->
 
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory


 <<O>>  Difference Topic TwistyPlugin (8 - 2012-11-15 - TWikiContributor)
 

TwistyPlugin

<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Twisty section JavaScript library to open/close content dynamically

Introduction

The TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:

  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
mode="div"
showlink="Show&nbsp;"
hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%"
hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
id="currentCustomerList"
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
showlink="Show..."
hidelink="Hide"
firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: Hide interface if no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
link=""
noscript="hide"
start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
link=""
start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
prefix="<h4>!!"
mode="div"
link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%"
suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadSheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.

  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.

  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link

  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link

  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section

  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure

  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens, TWiki:Main.PeterThoeny
Changed:
<
<
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2011 Peter Thoeny;
© 2005-2011 TWiki:TWiki.TWikiContributor
>
>
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2012 Peter Thoeny;
© 2005-2012 TWiki:TWiki.TWikiContributor
 
License: GPL (GNU General Public License)
Dependencies: None
Changed:
<
<
Plugin Version: 2011-07-10
>
>
Plugin Version: 2012-11-14
 
Change History:
<-- versions below in reverse order -->
 
Added:
>
>
2012-11-14: TWikibug:Item7020: Categorize TWiki Variable -- TWiki:Main.PeterThoeny
 
2011-07-10: TWikibug:Item6725: Change global package variables from "use vars" to "our"
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory


 <<O>>  Difference Topic TwistyPlugin (7 - 2011-07-10 - TWikiContributor)
 

TwistyPlugin

<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Twisty section JavaScript library to open/close content dynamically

Introduction

The TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:

  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
mode="div"
showlink="Show&nbsp;"
hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%"
hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
id="currentCustomerList"
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
showlink="Show..."
hidelink="Hide"
firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: Hide interface if no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
link=""
noscript="hide"
start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
link=""
start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
prefix="<h4>!!"
mode="div"
link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%"
suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadSheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.

  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.

  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link

  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link

  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section

  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure

  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Changed:
<
<
Authors: TWiki:Main/RafaelAlvarez, TWiki:Main/ArthurClemens, TWiki:Main/PeterThoeny
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010 Peter Thoeny;
© 2005-2010 TWiki:TWiki/TWikiContributor
>
>
Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens, TWiki:Main.PeterThoeny
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010-2011 Peter Thoeny;
© 2005-2011 TWiki:TWiki.TWikiContributor
 
License: GPL (GNU General Public License)
Dependencies: None
Changed:
<
<
Plugin Version: 2010-05-17 (version 1.6)
>
>
Plugin Version: 2011-07-10
 
Change History:
<-- versions below in reverse order -->
 
Added:
>
>
2011-07-10: TWikibug:Item6725: Change global package variables from "use vars" to "our"
 
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory


 <<O>>  Difference Topic TwistyPlugin (6 - 2010-11-05 - TWikiContributor)
 

TwistyPlugin

<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Changed:
<
<
>
>
 
Changed:
<
<
>
>
 Twisty section JavaScript library to open/close content dynamically

Introduction

The TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:

  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
mode="div"
showlink="Show&nbsp;"
hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%"
hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
id="currentCustomerList"
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
showlink="Show..."
hidelink="Hide"
firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: Hide interface if no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
link=""
noscript="hide"
start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
link=""
start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
prefix="<h4>!!"
mode="div"
link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%"
suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadSheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.

  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.

  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link

  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link

  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section

  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure

  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Authors: TWiki:Main/RafaelAlvarez, TWiki:Main/ArthurClemens, TWiki:Main/PeterThoeny
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010 Peter Thoeny;
© 2005-2010 TWiki:TWiki/TWikiContributor
License: GPL (GNU General Public License)
Dependencies: None
Plugin Version: 2010-05-17 (version 1.6)
Change History:
<-- versions below in reverse order -->
 
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory


 <<O>>  Difference Topic TwistyPlugin (5 - 2010-05-18 - TWikiContributor)
 

TwistyPlugin

Added:
>
>
<--
   Contributions to this TWiki plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/TwistyPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.
-->
Twisty section JavaScript library to open/close content dynamically
 
Changed:
<
<
A "twisty" is an interface toggle control to show and hide content.
>
>

Introduction

 
Changed:
<
<
TwistyPlugin gives you several options to control the appearance of a twisty:
>
>
The TwistyPlugin gives you several options to control the appearance of a twisty:
 
  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Deleted:
<
<
 

Usage examples

Added:
>
>
 

Triad

Added:
>
>
 A Twisty consists of 3 elements:
  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Twisty with icons

Added:
>
>
 We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
mode="div"
showlink="Show&nbsp;"
hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%"
hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->
Deleted:
<
<
 

Make it remember

Added:
>
>
 To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
id="currentCustomerList"
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"
Deleted:
<
<
 

Make it obey

Added:
>
>
 To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->
Deleted:
<
<
 

Make it obey only the first time

Deleted:
<
<
To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.
 
Added:
>
>
To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.
 
%TWISTY{
showlink="Show..."
hidelink="Hide"
firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->
Added:
>
>

Other use: Hide interface if no JavaScript

 
Deleted:
<
<

Other use: hide interface parts in case of no JavaScript

 You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
link=""
noscript="hide"
start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
link=""
start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->
Deleted:
<
<
 

Styling the Twisty

Added:
>
>
 Use parameter class to style the content div or class:

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->
Deleted:
<
<
 

Twisty headers

Added:
>
>
 To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
prefix="<h4>!!"
mode="div"
link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%"
suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>
Deleted:
<
<
 

Expand all   Collapse all

Deleted:
<
<
 

Special syntax: format tokens

Added:
>
>
 If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.
Changed:
<
<
The format tokens are the same as with FormattedSearch:
>
>
The format tokens are the same as with FormattedSearch:
 
Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)
Deleted:
<
<
 For example, to show an icon inside the link, do not write:
link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->
Changed:
<
<
Or a more complex example using SpreadsheetPlugin; do not write:
>
>
Or a more complex example using SpreadSheetPlugin; do not write:
 
link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

Added:
>
>
 This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
Changed:
<
<
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
>
>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
 
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Added:
>
>
 Twisty closure, complements the opening TWISTY tag.
  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Added:
>
>
 Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.
  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Added:
>
>
 Show/open link
  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
Changed:
<
<
img Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
imgright Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
>
>
img Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
imgright Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
 
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Added:
>
>
 Hide/close link
  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
Changed:
<
<
img Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
>
>
img Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
 
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Added:
>
>
 Twisty Toggle contents section
  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

Added:
>
>
 The Twisty closure
  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Changed:
<
<
Plugin settings are stored as preferences variables. To reference
>
>
Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%
Deleted:
<
<
a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%
 
  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

Added:
>
>
 
  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.
Deleted:
<
<
 

Plugin Info

Changed:
<
<
Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens
Copyright ©: 2005 Rafael Alvarez; 2006-2008 Arthur Clemens
License: GPL
>
>
Authors: TWiki:Main/RafaelAlvarez, TWiki:Main/ArthurClemens, TWiki:Main/PeterThoeny
Copyright: © 2005 Rafael Alvarez;
© 2006-2008 Arthur Clemens;
© 2010 Peter Thoeny;
© 2005-2010 TWiki:TWiki/TWikiContributor
License: GPL (GNU General Public License)
 
Dependencies: None
Changed:
<
<
Plugin Version: 10 Oct 2008 (version 1.4.12)
>
>
Plugin Version: 2010-05-17 (version 1.6)
 
Change History:
<-- versions below in reverse order -->
 
Added:
>
>
2010-05-17: 1.6 TWikibug:Item6433 - doc improvements -- Peter Thoeny
2010-03-31: 1.5 TWikibug:Item6354 - make TwistyPlugin work with TWiki:Plugins/VarCachePlugin; added VarTWISTY variable documentation -- Peter Thoeny
 
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal
Added:
>
>
Related Topics: TwistyContrib, VarTWISTY, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory
 

 <<O>>  Difference Topic TwistyPlugin (4 - 2007-11-19 - TWikiAdminUser)
 

TwistyPlugin

A "twisty" is an interface toggle control to show and hide content.

TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:
  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
mode="div"
showlink="Show&nbsp;"
hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%"
hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
id="currentCustomerList"
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
showlink="Show..."
Changed:
<
<
hidelink="Hide
>
>
hidelink="Hide"
 start="hide" }% my twisty content </>
<--/twistyPlugin-->

%TWISTY{ showlink="Show..."

Changed:
<
<
hidelink="Hide
>
>
hidelink="Hide"
 start="hide" }% my twisty content </>
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
showlink="Show..."
hidelink="Hide"
firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: hide interface parts in case of no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
link=""
noscript="hide"
start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
link=""
start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
prefix="<h4>!!"
mode="div"
link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%"
suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

%TWISTY{ prefix="

!!"

Added:
>
>
mode="div"
 link="Header" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix="" }% my twisty content </>
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadsheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
Changed:
<
<
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
>
>
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
 
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.
  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.
  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
Changed:
<
<
mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag optional, defaults to <span>
>
>
mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
Added:
>
>
  • Example: %TWISTYBUTTON{id="myid" link="more"}%%TWISTYTOGGLE{id="myid"}%content%ENDTWISTYTOGGLE%
 

TWISTYSHOW

Show/open link
Changed:
<
<
mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag optional, defaults to <span>
>
>
mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
 
img Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
imgright Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link
Changed:
<
<
mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag optional, defaults to <span>
>
>
mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
 
img Image url Specify the url of an image that will be displayed at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section
Changed:
<
<
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
>
>
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. Note that if the contents contains block elements such as div, mode should be div as well to create valid HTML markup. optional, defaults to <span>
 
class CSS class name Class for content div or span optional, default none
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript

ENDTWISTYTOGGLE

The Twisty closure
  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens
Changed:
<
<
Copyright ©: 2005 Rafael Alvarez; 2006, 2007 Arthur Clemens
>
>
Copyright ©: 2005 Rafael Alvarez; 2006-2008 Arthur Clemens
 
License: GPL
Dependencies: None
Changed:
<
<
Plugin Version: 03 Aug 2008 (version 1.4.10)
>
>
Plugin Version: 10 Oct 2008 (version 1.4.12)
 
Change History:
<-- versions below in reverse order -->
 
Added:
>
>
08 Oct 2008 1.4.11, 1.4.12 It is now possible to have a twisty on the same line without a linebreak.
 
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

 <<O>>  Difference Topic TwistyPlugin (3 - 2007-11-19 - TWikiAdminUser)
 

TwistyPlugin

A "twisty" is an interface toggle control to show and hide content.

TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.

Usage examples

Triad

A Twisty consists of 3 elements:
  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Shorthand

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{}%
my twisty content
%ENDTWISTY%

Will generate:

More... Close

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.

Twisty with icons

We will use mode="div" to put the collapsing content below the button (the default mode is "span").

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%"
hideimgleft="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{
mode="div"
showlink="Show&nbsp;"
hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%"
hideimgright="%ICONURLPATH{toggleclose-small}%"
}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{
showlink="Show..."
hidelink="Hide"
remember="off"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{
id="currentCustomerList"
showlink="Show..."
hidelink="Hide"
remember="on"
}%
my customer list
%ENDTWISTY%

Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:

id="%WEB%_%TOPIC%_currentCustomerList"

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{
showlink="Show..."
hidelink="Hide"
start="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{
showlink="Show..."
hidelink="Hide
start="hide"
}%
my twisty content
%ENDTWISTY%

Show... Hide start=

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{
showlink="Show..."
hidelink="Hide"
firststart="show"
}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: hide interface parts in case of no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{
link=""
noscript="hide"
start="show"
}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{
link=""
start="show"
}%
<input type="submit" class="twikiButton" value="You might have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{
mode="div"
showlink="Show..."
hidelink="Hide"
class="twikiHelp"
}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{
prefix="<h4>!!"
mode="div"
link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%"
suffix="</h4>"
}%
my twisty content
%ENDTWISTY%

Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.

Will create:

!! Header Header

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> &nbsp; <button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

 

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> &nbsp; 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all   Collapse all

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.

The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadsheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.
  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.
  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag optional, defaults to <span>
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link
  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link
  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section
  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure
  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    TwistyBundleTWiki04x02_installer  
    TwistyBundleTWiki04x02_installer.pl  
    data/TWiki/TwistyBundleTWiki04x02.txt  
    data/TWiki/BehaviourContrib.txt  
    data/TWiki/TwistyContrib.txt  
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Contrib/BehaviourContrib.pm  
    lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
    lib/TWiki/Contrib/TwistyContrib.pm  
    lib/TWiki/Plugins/TwistyPlugin.pm  
    pub/TWiki/BehaviourContrib/behaviour.compressed.js  
    pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
    pub/TWiki/BehaviourContrib/behaviour.js  
    pub/TWiki/BehaviourContrib/behaviour_src.js  
    pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
    pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
    pub/TWiki/BehaviourContrib/cssQuery/test.html  
    pub/TWiki/TwistyContrib/twist.compressed.js  
    pub/TWiki/TwistyContrib/twist.compressed_src.js  
    pub/TWiki/TwistyContrib/twist.css  
    pub/TWiki/TwistyContrib/twist.js  
    pub/TWiki/TwistyContrib/twist_src.js  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved. None
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Changed:
<
<
Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens
Copyright ©: 2005 Rafael Alvarez; 2006, 2007 Arthur Clemens
License: GPL
Dependencies: None
Plugin Version: 24 Nov 2007 (version 1.4.8)
Change History:
<-- versions below in reverse order -->
 
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal
>
>
Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens
Copyright ©: 2005 Rafael Alvarez; 2006, 2007 Arthur Clemens
License: GPL
Dependencies: None
Plugin Version: 03 Aug 2008 (version 1.4.10)
Change History:
<-- versions below in reverse order -->
 
03 Aug 2008 1.4.10 TWiki 4.2.1 release version
13 Dec 2007 1.4.9 fix to the loading order of javascript files in head
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Added:
>
>
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal
 

 <<O>>  Difference Topic TwistyPlugin (2 - 2007-11-19 - TWikiAdminUser)
 

TwistyPlugin

A "twisty" is an interface toggle control to show and hide content.

TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div
Changed:
<
<
Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden. Unless parameter noscript="hide" is used to specifically set the content to hide.
>
>
Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden.
 
Deleted:
<
<
What's new in version 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 setting
  • New properties prefix and suffix
  • JavaScript to collapse or expand all Twisties on the page
 

Usage examples

Triad

A Twisty consists of 3 elements:
  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%
Added:
>
>

Shorthand

 
Deleted:
<
<

Working Twisty

 The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
More... Close
<--/twistyPlugin twikiMakeVisibleInline-->
 my twisty content
<--/twistyPlugin-->
Changed:
<
<
It will look like this:
>
>
Will generate:
 
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
More... Close
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
 
<--/twistyPlugin-->
Added:
>
>
You may have noticed that no parameters are passed to %TWISTY{}% but the show and hide links do have text! The default values are fetched from plugin settings TWISTYSHOWLINK and TWISTYHIDELINK, see Plugin Settings below.
 

Twisty with icons

Changed:
<
<
We will use mode="div" to put the collapsing content below the button.
>
>
We will use mode="div" to put the collapsing content below the button (the default mode is "span").
 
Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{ mode="div" showlink="Show..."
Added:
>
>
hidelink="Hide" showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif" }%
 my twisty content
<--/twistyPlugin-->

It will look like this:

Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ mode="div" showlink="Show..." hidelink="Hide"
Added:
>
>
showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif" }% my twisty content
 
<--/twistyPlugin-->

To put icons at the right side, write

Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{ mode="div" showlink="Show "
Added:
>
>
hidelink="Hide " showimgright="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgright="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif" }%
 my twisty content
<--/twistyPlugin-->
Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ mode="div" showlink="Show " hidelink="Hide "
Added:
>
>
showimgright="/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif" hideimgright="/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif" }% my twisty content
 
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
showlink="Show..." hidelink="Hide" remember="on" }%
 my twisty content
<--/twistyPlugin-->
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ showlink="Show..."
Added:
>
>
hidelink="Hide" remember="on" }% my twisty content
 
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
showlink="Show..." hidelink="Hide" remember="off" }%
 my twisty content
<--/twistyPlugin-->
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ showlink="Show..."
Added:
>
>
hidelink="Hide" remember="off" }% my twisty content
 
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
id="currentCustomerList" showlink="Show..." hidelink="Hide" remember="on" }%
 my customer list
<--/twistyPlugin-->
Added:
>
>
Note that id sets a sitewide cookie. To create a unique id, add topic or web variables:
id="%WEB%_%TOPIC%_currentCustomerList"
 
Added:
>
>
 

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
showlink="Show..." hidelink="Hide" start="show" }%
 my twisty content
<--/twistyPlugin-->
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ showlink="Show..."
Added:
>
>
hidelink="Hide" start="show" }% my twisty content
 
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
showlink="Show..." hidelink="Hide start="hide" }%
 my twisty content
<--/twistyPlugin-->
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ showlink="Show..."
Added:
>
>
hidelink="Hide start="hide" }% my twisty content
 
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
showlink="Show..." hidelink="Hide" firststart="show" }%
 my twisty content
<--/twistyPlugin-->
Changed:
<
<
Show... Hide
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ showlink="Show..."
Added:
>
>
hidelink="Hide" firststart="show" }% my twisty content
 
<--/twistyPlugin-->

Other use: hide interface parts in case of no JavaScript

Added:
>
>
 You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
link="" noscript="hide" start="show" }%
 
<--/twistyPlugin-->
Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
link="" noscript="hide" start="show" }%
 
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{ link=""
Added:
>
>
start="show" }%
 
<--/twistyPlugin-->
Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{ link=""
Added:
>
>
start="show" }%
 
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:
Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
>
>
%TWISTY{
Added:
>
>
mode="div" showlink="Show..." hidelink="Hide" class="twikiHelp" }%
 my twisty content
<--/twistyPlugin-->

Generates:

Changed:
<
<
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
>
>
%TWISTY{ mode="div"
Added:
>
>
showlink="Show..." hidelink="Hide" class="twikiHelp" }% my twisty content
 
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.
Changed:
<
<
%TWISTY{prefix="

!!" link="Header"

>
>
%TWISTY{
Added:
>
>
prefix="

!!" mode="div" link="Header"

 showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen.gif"
Changed:
<
<
hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix=""}%
>
>
hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif"
Added:
>
>
suffix="" }%
 my twisty content
<--/twistyPlugin-->
Added:
>
>
Add the !! to prevent the twisty header appear in the table of contents when you use %TOC%.
 Will create:
Changed:
<
<
%TWISTY{prefix="

!!" link="Header"

>
>
%TWISTY{
Added:
>
>
prefix="

!!" link="Header"

 showimgleft="/pub/TWiki/TWikiDocGraphics/toggleopen.gif"
Changed:
<
<
hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix=""}% my twisty content
>
>
hideimgleft="/pub/TWiki/TWikiDocGraphics/toggleclose.gif" suffix=""
Added:
>
>
}% my twisty content
 
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

Changed:
<
<
>
>
 
Deleted:
<
<
 

Creates these controls:

Changed:
<
<
>
>
 
 

When you want to use links, write:

#VarTOGGLE
Changed:
<
<
Expand all
>
>
Expand all  
 Collapse all

Changed:
<
<
Expand all
>
>
Expand all  
 Collapse all
Added:
>
>

Special syntax: format tokens

If you use TWiki variables inside TWISTY parameters chances are it will mess up the variable, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed.
 
Added:
>
>
The format tokens are the same as with FormattedSearch:

Escape: Expands To:
$n or $n() New line. Use $n() if followed by alphanumeric character, e.g. write Foo$n()Bar instead of Foo$nBar
$nop or $nop() Is a "no operation".
$quot Double quote (")
$percnt Percent sign (%)
$dollar Dollar sign ($)

For example, to show an icon inside the link, do not write:

link="%Y%"

but use format tokens:

link="$percntY$percnt"

... to get:

DONE DONE
<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Or a more complex example using SpreadsheetPlugin; do not write:

link="Count: (%CALC{"$GET(infoCount)"}%)"

but use format tokens:

link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)"
 

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
Changed:
<
<
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
>
>
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
 

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.
  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.
  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag optional, defaults to <span>
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link
  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link
  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section
  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure
  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics
Added:
>
>
 

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
Added:
>
>
TwistyBundleTWiki04x02_installer  
TwistyBundleTWiki04x02_installer.pl  
data/TWiki/TwistyBundleTWiki04x02.txt  
data/TWiki/BehaviourContrib.txt  
data/TWiki/TwistyContrib.txt  
 
data/TWiki/TwistyPlugin.txt  
Added:
>
>
lib/TWiki/Contrib/BehaviourContrib.pm  
lib/TWiki/Contrib/TwistyBundleTWiki04x02.pm  
lib/TWiki/Contrib/TwistyContrib.pm  
 
lib/TWiki/Plugins/TwistyPlugin.pm  
Added:
>
>
pub/TWiki/BehaviourContrib/behaviour.compressed.js  
pub/TWiki/BehaviourContrib/behaviour.compressed_src.js  
pub/TWiki/BehaviourContrib/behaviour.js  
pub/TWiki/BehaviourContrib/behaviour_src.js  
pub/TWiki/BehaviourContrib/cssQuery/cssQuery-p.js  
pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level2.js  
pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-level3.js  
pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery-standard.js  
pub/TWiki/BehaviourContrib/cssQuery/src/cssQuery.js  
pub/TWiki/BehaviourContrib/cssQuery/src/test.html  
pub/TWiki/BehaviourContrib/cssQuery/test.html  
pub/TWiki/TwistyContrib/twist.compressed.js  
pub/TWiki/TwistyContrib/twist.compressed_src.js  
pub/TWiki/TwistyContrib/twist.css  
pub/TWiki/TwistyContrib/twist.js  
pub/TWiki/TwistyContrib/twist_src.js  
 
  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved.
Changed:
<
<
NameVersionDescription
TWiki::Contrib::TwistyContrib>=1.200Required. Twisty javascript library
>
>
None
 
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens
Changed:
<
<
Copyright ©: 2005 Rafael Alvarez, 2006 Arthur Clemens
>
>
Copyright ©: 2005 Rafael Alvarez; 2006, 2007 Arthur Clemens
 
License: GPL
Changed:
<
<
Dependencies:
NameVersionDescription
TWiki::Contrib::TwistyContrib>=1.200Required. Twisty javascript library
>
>
Dependencies: None
Added:
>
>
Plugin Version: 24 Nov 2007 (version 1.4.8)
Change History:
<-- versions below in reverse order -->
 
24 Nov 2007 1.4.6 - 1.4.8 Arthur Clemens - Added format tokens.
07 Oct 2007 1.4.5 Arthur Clemens - Fix html tag with show/hide controls.
25 Sep 2007 1.4.4 Arthur Clemens - Fix rendering of headers when prefix is used.
11 Jul 2007 1.4.3 Arthur Clemens - Fix invalid html when prefix and suffix is used.
23 Jun 2007 1.4.2 Arthur Clemens - Fixed bugs with parameters firststart and noscript (since version 1.4).
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.
19 Jun 2006 1.3 Arthur Clemens - Updated with TWiki 4 JavaScript files.
 
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

 <<O>>  Difference Topic TwistyPlugin (1 - 2005-11-01 - TWikiContributor)
 

TwistyPlugin

A "twisty" is an interface toggle control to show and hide content.

TwistyPlugin gives you several options to control the appearance of a twisty:

  • use link text or buttons
  • position an icon left or right
  • remember the state at the next visit of the page
  • start the Twisty open or closed
  • start the Twisty open or closed for the first visit
  • use a span or div for the content
  • set a class for the content span or div

Twisty has a fallback mechanism in case JavaScript is not available: all content is displayed and the control buttons are hidden. Unless parameter noscript="hide" is used to specifically set the content to hide.

What's new in version 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 setting
  • New properties prefix and suffix
  • JavaScript to collapse or expand all Twisties on the page

Usage examples

Triad

A Twisty consists of 3 elements:
  1. Show button
  2. Hide button
  3. Collapsing content ('Toggle')

The typical TwistyPlugin triad will look like this (pseudo code):

%TWISTYSHOW{}% %TWISTYHIDE{}%
(there may be other things between buttons and content)
%TWISTYTOGGLE{}% my content %ENDTWISTYTOGGLE%

Working Twisty

The Twisty triad is conveniently packed into shorthand %TWISTY{some parameters}% Collapsing content %ENDTWISTY%:

%TWISTY{showlink="Show..." hidelink="Hide"}%
my twisty content
%ENDTWISTY%

It will look like this:

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty with icons

We will use mode="div" to put the collapsing content below the button.

%TWISTY{mode="div" showlink="Show..." hidelink="Hide"
showimgleft="%ICONURLPATH{toggleopen-small}%" 
hideimgleft="%ICONURLPATH{toggleclose-small}%"}%
my twisty content
%ENDTWISTY%

It will look like this:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

To put icons at the right side, write

%TWISTY{mode="div" showlink="Show&nbsp;" hidelink="Hide&nbsp;"
showimgright="%ICONURLPATH{toggleopen-small}%" 
hideimgright="%ICONURLPATH{toggleclose-small}%"}%
my twisty content
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it remember

To store the last state in a TWIKIPREF cookie, add the parameter remember="on".
To test this, reload the page after toggling.

%TWISTY{showlink="Show..." hidelink="Hide" remember="on"}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

If a Twisty state has been stored in a TWIKIPREF cookie before, it can be cleared by using remember="off":

%TWISTY{showlink="Show..." hidelink="Hide" remember="off"}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

NOTE: Twisty ids are generated automatically. If you need control over exactly which Twisty should be remembered, add the parameter id:

%TWISTY{id="currentCustomerList" showlink="Show..." hidelink="Hide" remember="on"}%
my customer list
%ENDTWISTY%

Make it obey

To let the Twisty start with its content folded open, add parameter start="show".

%TWISTY{showlink="Show..." hidelink="Hide" start="show"}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Likewise use start="hide" to start with hidden content.

%TWISTY{showlink="Show..." hidelink="Hide" start="hide"}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Make it obey only the first time

To let the Twisty start with its content folded open the first time the visitor sees the Twisty, add the parameter firststart="show". If remember="on" is used, subsequential visits to the page will display the Twisty according the cookie setting.

%TWISTY{showlink="Show..." hidelink="Hide" firststart="show"}%
my twisty content
%ENDTWISTY%

Show... Hide

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Other use: hide interface parts in case of no JavaScript

You 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.

Put the "JavaScript content" in an almost bare bones Twisty. Write showlink="" hidelink="" to not display any default link texts.

%TWISTY{link="" noscript="hide" start="show"}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Do not forget to set start="show" to show the Twisty content at all.

When JavaScript is off, the button should be invisible.

This code will show the button when JavaScript is off:

%TWISTY{link="" start="show"}%
<input type="submit" class="twikiButton" value="You surely have !JavaScript" />
%ENDTWISTY%

<--/twistyPlugin twikiMakeVisibleInline-->
<--/twistyPlugin-->

Styling the Twisty

Use parameter class to style the content div or class:

%TWISTY{mode="div" showlink="Show..." hidelink="Hide" class="twikiHelp"}%
my twisty content
%ENDTWISTY%

Generates:

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

Twisty headers

To be able to use header tags like <h2>, use the properties prefix and suffix. Because we have identical show and hide links we can use the shorthand property link.

%TWISTY{prefix="<h4>!!" link="Header"
showimgleft="%ICONURLPATH{toggleopen}%"
hideimgleft="%ICONURLPATH{toggleclose}%" suffix="</h4>"}%
my twisty content
%ENDTWISTY%

Will create:

!! Header Header

<--/twistyPlugin twikiMakeVisibleInline-->
my twisty content
<--/twistyPlugin-->

All on, all off

You can toggle all Twisties on or off at once by putting a link or button on the page with class twistyExpandAll or twistyCollapseAll.

<button class="twistyExpandAll twikiButton">Expand all</button> 
<button class="twistyCollapseAll twikiButton">Collapse all</button>

Creates these controls:

When you want to use links, write:

#VarTOGGLE

<a href="#TOGGLE" class="twistyExpandAll">Expand all</a> 
<a href="#TOGGLE" class="twistyCollapseAll">Collapse all</a>

Expand all Collapse all

Syntax

TWISTY

This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag.
Usage: %TWISTY{ ... }% Toggable contents %ENDTWISTY%

Parameter Value Description Remark
id Unique identifier Used to link TWISTYBUTTON and TWISTYTOGGLE optional
link Link label Link label for both show and hide links optional
hidelink Link label Hide link label optional
showlink Link label Show link label optional
mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
showimgleft Image url Specify the url of an image that will be displayed with the show link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgleft Image url Specify the url of an image that will be displayed with the hide link at the left side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
showimgright Image url Specify the url of an image that will be displayed with the show link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
hideimgright Image url Specify the url of an image that will be displayed with the hide link at the right side of the link.
You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
optional, defaults to no image
remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
optional, no default
start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown in case JavaScript if off
class CSS class name Class for Twisty div or span optional, default none
prefix Text Text to display before the show/hide links optional, default none
suffix Text Text to display after the show/hide links optional, default none
img Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgleft Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
imgright Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
hideimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image
showimg Image url Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright. optional, defaults to no image

ENDTWISTY

Twisty closure, complements the opening TWISTY tag.
  • Syntax: %ENDTWISTY%

See ENDTWISTYTOGGLE.

Twisty components syntax

Ocassionally you might need to create a custom set of individual Twisty components:

TWISTYBUTTON

Shorthand version for TWISTYSHOW & TWISTYHIDE This is useful if both the show and the hide button take the same arguments.
  • Supported parameters: all parameters supported by TWISTY, except for noscript and class (only used for 'toggle' content)
  • Parameter differences:
    • mode: button mode defaults to span
  • Syntax: %TWISTYBUTTON{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    mode "div" or "span" Specify if the Twisty button will use a <div> or a <span> tag optional, defaults to <span>
  • Related: TWISTYSHOW and TWISTYHIDE

TWISTYSHOW

Show/open link
  • Syntax: %TWISTYSHOW{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Show link label optional
    mode "div" or "span" Specify if the Twisty Show link will use a <div> or a <span> tag optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgleft Image url Specify the url of an image that will be displayed at the left side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    imgright Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYSHOW{id="demo" link=" Click to Unfold " imgleft="%ICONURLPATH{toggleopen}%"}%
  • Related: TWISTYHIDE and TWISTYTOGGLE

TWISTYHIDE

Hide/close link
  • Syntax: %TWISTYHIDE{id="myid" ... }%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE required
    link Link label Hide link label optional
    mode "div" or "span" Specify if the Twisty Hide link will use a <div> or a <span> tag optional, defaults to <span>
    img Image url Specify the url of an image that will be displayed at the right side of the link.
    You may use ICONURLPATH to display one of the TWikiDocGraphics icons. Alternatively use an image attached to the topic.
    optional, defaults to no image
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
  • Example: %TWISTYHIDE{id="demo" link=" Click to Fold " imgleft="%ICONURLPATH{toggleclose}%"}%
  • Related: TWISTYSHOW and TWISTYTOGGLE

TWISTYTOGGLE

Twisty Toggle contents section
  • Syntax: %TWISTYTOGGLE{id="myid"}%
  • Supported parameters:
    Parameter Value Description Remark
    id Unique identifier Used to link TWISTYSHOW, TWISTYHIDE and TWISTYTOGGLE. required
    mode "div" or "span" Specify if the Twisty Toggle section will use a <div> or a <span> tag. optional, defaults to <span>
    class CSS class name Class for content div or span optional, default none
    remember "on", "off" If "on", the Twisty state is remembered the next time the page is shown. If "off", the stored setting will be cleared.
    Note: when used, think carefully about a unique name (id) for the Twisty, otherwise the cookie that is set might affect other Twisties with the same name. Also note that only interaction is stored, not the state of the Twisty when left unclicked.
    optional, no default
    start "hide" or "show" Initial state of the Twisty; this will override any setting stored in a cookie (see remember). optional, default no initial state
    firststart "hide" or "show" Initial state of the Twisty the first time the visitor gets to see the Twisty; this will NOT override cookie settings (see remember). optional, default no initial state
    noscript "hide" Make content hidden in case use does not have JavaScript on optional, default content is shown with no JavaScript
  • Example: %TWISTYTOGGLE{id="demo" mode="div" remember="on"}%My content%ENDTWISTYTOGGLE%
  • Related: TWISTYHIDE, TWISTYHIDE an ENDTWISTYTOGGLE

ENDTWISTYTOGGLE

The Twisty closure
  • Syntax: %ENDTWISTYTOGGLE%
    • Will end the most inner unclosed Twisty Toggle section, using the proper tag
  • Example: %ENDTWISTYTOGGLE%
  • Related: TWISTYTOGGLE

The Fine Print

TwistyPlugin is a convenience plugin for TWiki:Plugins.TwistyContrib.

Major features are:

  • When active, the Twisty JavaScript library is included in every topic
  • Provides a convenience syntax to define Twisty areas
  • Automatically generates ids
  • Automatically fills in default values
  • Global preference settings can be set in this topic or locally in individual topics

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %TWISTYPLUGIN_SHORTDESCRIPTION%

  • Set TWISTYSHOWLINK = More...
    • For example: More...
  • Set TWISTYHIDELINK = Close
    • For example: Close
  • Set TWISTYMODE =
    • Either div or span; span if nothing set
  • Set TWISTYREMEMBER =
    • Either on or off; default is not specified. If set to on all Twisty states will be stored in a TWIKIPREF cookie; if set to off the TWIKIPREF cookie will be cleared

  • Set SHORTDESCRIPTION = Twisty section JavaScript library to open/close content dynamically
  • Set DEBUG = 0

Plugin Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip TwistyPlugin.zip in your root ($TWIKI_ROOT) directory. Content:
    File: Description:
    data/TWiki/TwistyPlugin.txt  
    lib/TWiki/Plugins/TwistyPlugin.pm  

  • Optionally, if it exists, run TwistyPlugin_installer to automatically check and install other TWiki modules that this module depends on. You can also do this step manually.
  • Alternatively, manually make sure the dependencies listed in the table below are resolved.
    NameVersionDescription
    TWiki::Contrib::TwistyContrib>=1.200Required. Twisty javascript library
  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Authors: TWiki:Main.RafaelAlvarez, TWiki:Main.ArthurClemens
Copyright ©: 2005 Rafael Alvarez, 2006 Arthur Clemens
License: GPL
Dependencies:
NameVersionDescription
TWiki::Contrib::TwistyContrib>=1.200Required. Twisty javascript library
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.
27 Sep 2006 1.101 Fixes JavaScript handling when AllowInlineScript in configure is not set
11 June 2006 1.100 Added parameters start, firststart, noscript and class; complete JavaScript rewrite for speed
12 Sep 2005 1.000 First Version
Home: http://TWiki.org/cgi-bin/view/Plugins/TwistyPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/TwistyPluginAppraisal

View | History: r12 < r11 < r10 < r9 | More

This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.TwistyPlugin.

(%REVTITLE2% vs. %REVTITLE1%) TwistyPlugin < TWiki < TWiki