From 0c5aec02f2b4753ddad04259399860b9da5df95b Mon Sep 17 00:00:00 2001 From: KennethLavrsen Date: Thu, 26 Feb 2009 16:53:27 +0000 Subject: [PATCH] Item1156: Create Release01x00 branch git-svn-id: http://svn.foswiki.org/branches/Release01x00@2736 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- TwistyPlugin/data/System/TwistyPlugin.txt | 623 ++++++++++++++++++ .../lib/Foswiki/Plugins/TwistyPlugin.pm | 437 ++++++++++++ .../Foswiki/Plugins/TwistyPlugin/DEPENDENCIES | 3 + .../lib/Foswiki/Plugins/TwistyPlugin/MANIFEST | 11 + .../lib/Foswiki/Plugins/TwistyPlugin/build.pl | 18 + .../pub/System/TwistyPlugin/twisty.css | 20 + .../pub/System/TwistyPlugin/twisty.dojo.js | 266 ++++++++ .../pub/System/TwistyPlugin/twisty.jquery.css | 20 + .../pub/System/TwistyPlugin/twisty.jquery.js | 247 +++++++ .../pub/System/TwistyPlugin/twisty.js | 252 +++++++ TwistyPlugin/templates/twistyplugin.dojo.tmpl | 15 + .../templates/twistyplugin.jquery.tmpl | 9 + .../templates/twistyplugin.pattern.tmpl | 10 + TwistyPlugin/templates/twistyplugin.tmpl | 12 + .../unit/TwistyPlugin/TwistyPluginSuite.pm | 6 + .../unit/TwistyPlugin/TwistyPluginTests.pm | 233 +++++++ 16 files changed, 2182 insertions(+) create mode 100644 TwistyPlugin/data/System/TwistyPlugin.txt create mode 100644 TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm create mode 100644 TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/DEPENDENCIES create mode 100644 TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/MANIFEST create mode 100755 TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/build.pl create mode 100644 TwistyPlugin/pub/System/TwistyPlugin/twisty.css create mode 100644 TwistyPlugin/pub/System/TwistyPlugin/twisty.dojo.js create mode 100644 TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.css create mode 100644 TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.js create mode 100644 TwistyPlugin/pub/System/TwistyPlugin/twisty.js create mode 100644 TwistyPlugin/templates/twistyplugin.dojo.tmpl create mode 100644 TwistyPlugin/templates/twistyplugin.jquery.tmpl create mode 100644 TwistyPlugin/templates/twistyplugin.pattern.tmpl create mode 100644 TwistyPlugin/templates/twistyplugin.tmpl create mode 100644 TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginSuite.pm create mode 100644 TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginTests.pm diff --git a/TwistyPlugin/data/System/TwistyPlugin.txt b/TwistyPlugin/data/System/TwistyPlugin.txt new file mode 100644 index 0000000000..b62121fbaf --- /dev/null +++ b/TwistyPlugin/data/System/TwistyPlugin.txt @@ -0,0 +1,623 @@ +%META:TOPICINFO{author="ProjectContributor" date="1195487956" format="1.1" version="1.1"}% +---+!! %TOPIC% + +*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. + +%TOC{title="On this page:"}% + +---++ Usage examples +---+++ Triad +A Twisty consists of 3 elements: + 1 Show button + 1 Hide button + 1 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: + +%TWISTY{}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + +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 [[#PluginSettings][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: + +%TWISTY{ +mode="div" +showlink="Show..." +hidelink="Hide" +showimgleft="%ICONURLPATH{toggleopen-small}%" +hideimgleft="%ICONURLPATH{toggleclose-small}%" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + +To put icons at the right side, write + +%TWISTY{ +mode="div" +showlink="Show " +hidelink="Hide " +showimgright="%ICONURLPATH{toggleopen-small}%" +hideimgright="%ICONURLPATH{toggleclose-small}%" +}% +my twisty content +%ENDTWISTY% + + +%TWISTY{ +mode="div" +showlink="Show " +hidelink="Hide " +showimgright="%ICONURLPATH{toggleopen-small}%" +hideimgright="%ICONURLPATH{toggleclose-small}%" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + + + +---+++ Make it remember +To store the last state in a FOSWIKIPREF cookie, add the parameter =remember="on"=.%BR% +To test this, reload the page after toggling. + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +remember="on" +}% +my twisty content +%ENDTWISTY% + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +remember="on" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + +If a Twisty state has been stored in a FOSWIKIPREF cookie before, it can be cleared by using =remember="off"=: + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +remember="off" +}% +my twisty content +%ENDTWISTY% + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +remember="off" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + +*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 macros: + +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% + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +start="show" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + +Likewise use =start="hide"= to start with hidden content. + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +start="hide" +}% +my twisty content +%ENDTWISTY% + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +start="hide" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + + + +---+++ 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% + + +%TWISTY{ +showlink="Show..." +hidelink="Hide" +firststart="show" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + + +---+++ 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" +}% + +%ENDTWISTY% + + +%TWISTY{ +link="" +noscript="hide" +start="show" +}% + +%ENDTWISTY% + +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" +}% + +%ENDTWISTY% + + +%TWISTY{ +link="" +start="show" +}% + +%ENDTWISTY% + + + +---+++ Styling the Twisty +Use parameter =class= to style the content div or class: + + +%TWISTY{ +mode="div" +showlink="Show..." +hidelink="Hide" +class="foswikiHelp" +}% +my twisty content +%ENDTWISTY% + + +Generates: %BR% +%TWISTY{ +mode="div" +showlink="Show..." +hidelink="Hide" +class="foswikiHelp" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + + +---+++ Styling the Twisty link or button +Use parameter =linkclass= to style the twisty links: + + +%TWISTY{ +mode="div" +showlink="Show..." +hidelink="Hide" +linkclass="foswikiButton" +}% +my twisty content +%ENDTWISTY% + + +Generates: %BR% +%TWISTY{ +mode="div" +showlink="Show..." +hidelink="Hide" +linkclass="foswikiButton" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + + +---+++ 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="

" +mode="div" +link="Twisty Header" +showimgleft="%ICONURLPATH{toggleopen}%" +hideimgleft="%ICONURLPATH{toggleclose}%" +suffix="

" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% +
+ +Will create: + +%TWISTY{ +prefix="

" +mode="div" +link="Twisty Header" +showimgleft="%ICONURLPATH{toggleopen}%" +hideimgleft="%ICONURLPATH{toggleclose}%" +suffix="

" +}% +%GREEN% my twisty content %ENDCOLOR% +%ENDTWISTY% + +---+++ 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=. + + +   + + +Creates these controls: + +   + + +When you want to use links, write: + + +#VarTOGGLE + +Expand all   +Collapse all + + + +#VarTOGGLE + +Expand all   +Collapse all + + +---++ Special syntax: format tokens +If you use other macros inside TWISTY parameters chances are it will mess up the macro, or the rendered html. Use format tokens to 'delay' rendering of these variables until the Twisty parameters are parsed. + +The format tokens are the same as with %SYSTEMWEB%.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: + +%TWISTY{ +mode="div" +link="$percntY$percnt" +showimgleft="%ICONURLPATH{toggleopen-small}%" +hideimgleft="%ICONURLPATH{toggleclose-small}%" +}% +my twisty content +%ENDTWISTY% + +Or a more complex example using %SYSTEMWEB%.SpreadSheetPlugin; do not write: + + +link="Count: (%CALC{"$GET(infoCount)"}%)" + + +but use format tokens: + + +link="Count: ($percntCALC{$quot$dollarGET(infoCount)$quot}$percnt)" + + + +---++ Syntax + +#VarTWISTY +---+++ TWISTY +This renders the button as well as the toggled content section contained within this and the closing ENDTWISTY tag. %BR% +Usage: =%TWISTY{ ... }% Toggable contents %ENDTWISTY%= + + | *Parameter* | *Value* | *Description* | *Remark* | + | =id= | Unique identifier | Used to link [[#VarTWISTYBUTTON][TWISTYBUTTON]] and [[#VarTWISTYTOGGLE][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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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 | + | =linkclass= | CSS class name | Class for link | 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 | %GREEN%Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright.%ENDCOLOR% | optional, defaults to no image | + | =imgleft= | Image url | %GREEN%Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright.%ENDCOLOR% | optional, defaults to no image | + | =imgright= | Image url | %GREEN%Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright.%ENDCOLOR% | optional, defaults to no image | + | =hideimg= | Image url | %GREEN%Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright.%ENDCOLOR% | optional, defaults to no image | + | =showimg= | Image url | %GREEN%Deprecated, use showimgleft, hideimgleft, showimgright or hideimgright.%ENDCOLOR% | optional, defaults to no image | + * Related [[#VarTWISTYSHOW][TWISTYBUTTON]] and [[#VarTWISTYTOGGLE][TWISTYTOGGLE]] + +#VarENDTWISTY +---+++ ENDTWISTY +*Twisty closure, complements the opening TWISTY tag.* + * Syntax: =%ENDTWISTY%= + +See [[#VarENDTWISTYTOGGLE][ENDTWISTYTOGGLE]]. + +---++ Twisty components syntax + +
+ +Ocassionally you might need to create a custom set of individual Twisty components: + +#VarTWISTYBUTTON +---+++ 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 [[#VarTWISTYSHOW][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: [[#VarTWISTYSHOW][TWISTYSHOW]] and [[#VarTWISTYHIDE][TWISTYHIDE]] + +#VarTWISTYSHOW +---+++ TWISTYSHOW +*Show/open link* + * Syntax: =%TWISTYSHOW{id="myid" ... }%= + * Supported parameters: + | *Parameter* | *Value* | *Description* | *Remark* | + | =id= | Unique identifier | Used to link [[#VarTWISTYSHOW][TWISTYSHOW]], [[#VarTWISTYHIDE ][TWISTYHIDE ]] and [[#VarTWISTYTOGGLE][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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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: [[#VarTWISTYHIDE][TWISTYHIDE]] and [[#VarTWISTYTOGGLE][TWISTYTOGGLE]] + +#VarTWISTYHIDE +---+++ TWISTYHIDE +*Hide/close link* + * Syntax: =%TWISTYHIDE{id="myid" ... }%= + * Supported parameters: + | *Parameter* | *Value* | *Description* | *Remark* | + | =id= | Unique identifier | Used to link [[#VarTWISTYSHOW][TWISTYSHOW]], [[#VarTWISTYHIDE ][TWISTYHIDE ]] and [[#VarTWISTYTOGGLE][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 [[%SYSTEMWEB%.Macros#VarICONURLPATH][ICONURLPATH]] to display one of the %SYSTEMWEB%.DocumentGraphics 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: [[#VarTWISTYSHOW][TWISTYSHOW]] and [[#VarTWISTYTOGGLE][TWISTYTOGGLE]] + +#VarTWISTYTOGGLE +---+++ TWISTYTOGGLE +*Twisty Toggle contents section* + * Syntax: =%TWISTYTOGGLE{id="myid"}%= + * Supported parameters: + | *Parameter* | *Value* | *Description* | *Remark* | + | =id= | Unique identifier | Used to link [[#VarTWISTYSHOW][TWISTYSHOW]], [[#VarTWISTYHIDE ][TWISTYHIDE ]] and [[#VarTWISTYTOGGLE][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 | + | =linkclass= | CSS class name | Class for link | 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: [[#VarTWISTYHIDE][TWISTYHIDE]], [[#VarTWISTYHIDE][TWISTYHIDE]] an [[#VarENDTWISTYTOGGLE][ENDTWISTYTOGGLE]] + +#VarENDTWISTYTOGGLE +---+++ ENDTWISTYTOGGLE +*The Twisty closure* + * Syntax: =%ENDTWISTYTOGGLE%= + * Will end the most inner unclosed Twisty Toggle section, using the proper tag + * Example: =%ENDTWISTYTOGGLE%= + * Related: [[#VarTWISTYTOGGLE][TWISTYTOGGLE]] +
+ +---++ Working with other Javascript libraries + +If you want to use a different Javascript library than the default Foswiki Javascripts, add to the skin path: + * =jquery= to use [[http://jquery.com/][JQuery]] + * For example, append to the url: =?skin=jquery,nat= %BR% + or write: =Set SKIN = jquery,nat= + * For this, Foswiki:Extensions/JQueryPlugin needs to be installed + * =dojo= to use [[http://jquery.com/][JQuery]] + * For example, append to the url: =?skin=dojo,pattern= %BR% + or write: =Set SKIN = dojo,pattern= + * For this, Foswiki:Extensions/DojoToolkitContrib needs to be installed + +#PluginSettings +---++ Plugin Settings + +Plugin settings are stored as [[%SYSTEMWEB%.PreferenceSettings][preference settings]]. To reference +a plugin setting write ==%<plugin>_<setting>%==, i.e. ==%TWISTYPLUGIN_SHORTDESCRIPTION%== + + * Set TWISTYSHOWLINK = %MAKETEXT{"More..."}% + * For example: =More...= + * Set TWISTYHIDELINK = %MAKETEXT{"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 FOSWIKIPREF cookie; if set to =off= the FOSWIKIPREF 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 it in your Foswiki installation directory. Content: + | *File:* | *Description:* | +%$MANIFEST% + + * Optionally, if it exists, run ==%TOPIC%_installer== to automatically check and install other Foswiki 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. +%$DEPENDECIES% + * Visit =configure= in your Foswiki installation, and enable the plugin in the {Plugins} section. + + +---++ Plugin Info + +| Authors: | Foswiki:Main.RafaelAlvarez, Foswiki:Main.MichaelDaum, Foswiki:Main.ArthurClemens | +| Copyright | Copyright (C) Rafael Alvarez; Michael Daum, Arthur Clemens | +| License: | [[http://www.gnu.org/copyleft/gpl.html][GPL]] | +| Plugin Version: | 29 Jan 2009 (version 1.5.2) | +| Change History: |   | +| 03 Dec 2008 | 1.5.1 Added parameter =linkclass=. Foswiki version | +| 27 Nov 2008 | 1.5 Foswiki release; added option to use other Javascript libraries. | +| 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 | +| Dependencies: | None | +| Home: | http://foswiki.org/Extensions/%TOPIC% | +| Support: | http://foswiki.org/Support/%TOPIC% | diff --git a/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm new file mode 100644 index 0000000000..c1739b5048 --- /dev/null +++ b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm @@ -0,0 +1,437 @@ +# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ +# +# Copyright (C) Michael Daum +# Copyright (C) Arthur Clemens, arthur@visiblearea.com +# Copyright (C) Rafael Alvarez, soronthar@sourceforge.net +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details, published at +# http://www.gnu.org/copyleft/gpl.html +# + +=begin TML + +---+ package TwistyPlugin + +=cut + +package Foswiki::Plugins::TwistyPlugin; + +use Foswiki::Func; +use CGI::Cookie; +use strict; + +use vars + qw( $VERSION $RELEASE $pluginName @modes $doneHeader $doneDefaults $twistyCount + $prefMode $prefShowLink $prefHideLink $prefRemember); + +# This should always be $Rev$ so that Foswiki can determine the checked-in +# status of the plugin. It is used by the build automation tools, so +# you should leave it alone. +$VERSION = '$Rev$'; + +# This is a free-form string you can use to "name" your own plugin version. +# It is *not* used by the build automation tools, but is reported as part +# of the version number in PLUGINDESCRIPTIONS. +$RELEASE = '1.5.2'; + +$pluginName = 'TwistyPlugin'; + +my $TWISTYPLUGIN_COOKIE_PREFIX = "TwistyPlugin_"; +my $TWISTYPLUGIN_CONTENT_HIDDEN = 0; +my $TWISTYPLUGIN_CONTENT_SHOWN = 1; + +#there is no need to document this. +sub initPlugin { + my ( $topic, $web, $user, $installWeb ) = @_; + + # check for Plugins.pm versions + if ( $Foswiki::Plugins::VERSION < 1.1 ) { + Foswiki::Func::writeWarning( + "Version mismatch between $pluginName and Plugins.pm"); + return 0; + } + + $doneDefaults = 0; + $doneHeader = 0; + $twistyCount = 0; + + Foswiki::Func::registerTagHandler( 'TWISTYSHOW', \&_TWISTYSHOW ); + Foswiki::Func::registerTagHandler( 'TWISTYHIDE', \&_TWISTYHIDE ); + Foswiki::Func::registerTagHandler( 'TWISTYBUTTON', \&_TWISTYBUTTON ); + Foswiki::Func::registerTagHandler( 'TWISTY', \&_TWISTY ); + Foswiki::Func::registerTagHandler( 'ENDTWISTY', \&_ENDTWISTYTOGGLE ); + Foswiki::Func::registerTagHandler( 'TWISTYTOGGLE', \&_TWISTYTOGGLE ); + Foswiki::Func::registerTagHandler( 'ENDTWISTYTOGGLE', \&_ENDTWISTYTOGGLE ); + + return 1; +} + +sub _setDefaults { + return if $doneDefaults; + $doneDefaults = 1; + + $prefMode = + Foswiki::Func::getPreferencesValue('TWISTYMODE') + || Foswiki::Func::getPluginPreferencesValue('TWISTYMODE') + || 'span'; + $prefShowLink = + Foswiki::Func::getPreferencesValue('TWISTYSHOWLINK') + || Foswiki::Func::getPluginPreferencesValue('TWISTYSHOWLINK') + || ''; + $prefHideLink = + Foswiki::Func::getPreferencesValue('TWISTYHIDELINK') + || Foswiki::Func::getPluginPreferencesValue('TWISTYHIDELINK') + || ''; + $prefRemember = + Foswiki::Func::getPreferencesValue('TWISTYREMEMBER') + || Foswiki::Func::getPluginPreferencesValue('TWISTYREMEMBER') + || ''; + +} + +sub _addHeader { + return if $doneHeader; + $doneHeader = 1; + + # Untaint is required if use locale is on + Foswiki::Func::loadTemplate( + Foswiki::Sandbox::untaintUnchecked(lc($pluginName)) ); + my $header = Foswiki::Func::expandTemplate('twisty:header'); + Foswiki::Func::addToHEAD( $pluginName, $header ); +} + +sub _TWISTYSHOW { + my ( $session, $params, $theTopic, $theWeb ) = @_; + _setDefaults(); + + my $mode = $params->{'mode'} || $prefMode; + my $btn = _twistyBtn( 'show', @_ ); + return Foswiki::Func::decodeFormatTokens( + _wrapInButtonHtml( $btn, $mode ) ); +} + +sub _TWISTYHIDE { + my ( $session, $params, $theTopic, $theWeb ) = @_; + _setDefaults(); + my $mode = $params->{'mode'} || $prefMode; + my $btn = _twistyBtn( 'hide', @_ ); + return Foswiki::Func::decodeFormatTokens( + _wrapInButtonHtml( $btn, $mode ) ); +} + +sub _TWISTYBUTTON { + my ( $session, $params, $theTopic, $theWeb ) = @_; + _setDefaults(); + + my $mode = $params->{'mode'} || $prefMode; + my $btnShow = _twistyBtn( 'show', @_ ); + my $btnHide = _twistyBtn( 'hide', @_ ); + my $prefix = $params->{'prefix'} || ''; + my $suffix = $params->{'suffix'} || ''; + my $btn = $prefix . $btnShow . $btnHide . $suffix; + return Foswiki::Func::decodeFormatTokens( + _wrapInButtonHtml( $btn, $mode ) ); +} + +sub _TWISTY { + my ( $session, $params, $theTopic, $theWeb ) = @_; + + _addHeader(); + $twistyCount++; + my $id = $params->{'id'}; + if ( !defined $id || $id eq '' ) { + $params->{'id'} = _createId( $params->{'id'}, $theWeb, $theTopic ); + } + return _TWISTYBUTTON(@_) . _TWISTYTOGGLE(@_); +} + +sub _TWISTYTOGGLE { + my ( $session, $params, $theTopic, $theWeb ) = @_; + my $id = $params->{'id'}; + if ( !defined $id || $id eq '' ) { + return ''; + } + _setDefaults(); + my $idTag = $id . 'toggle'; + my $mode = $params->{'mode'} || $prefMode; + unshift @modes, $mode; + + my $isTrigger = 0; + my $cookieState = _readCookie( $session, $idTag ); + my @propList = + _createHtmlProperties( undef, $idTag, $mode, $params, $isTrigger, + $cookieState ); + my $props = @propList ? " " . join( " ", @propList ) : ''; + my $modeTag = '<' . $mode . $props . '>'; + return Foswiki::Func::decodeFormatTokens( + _wrapInContentHtmlOpen($mode) . $modeTag ); +} + +sub _ENDTWISTYTOGGLE { + my ( $session, $params, $theTopic, $theWeb ) = @_; + my $mode = shift @modes; + + return +"woops, ordering error: got an ENDTWISTY before seeing a TWISTY" + unless $mode; + + my $modeTag = ($mode) ? '' : ''; + return $modeTag . _wrapInContentHtmlClose($mode); +} + +sub _createId { + my ( $rawId, $theWeb, $theTopic ) = @_; + + if ( !defined $rawId || $rawId eq '' ) { + return 'twistyId' . $theWeb . $theTopic . $twistyCount; + } + return "twistyId$rawId"; +} + +sub _twistyBtn { + my ( $twistyControlState, $session, $params, $theTopic, $theWeb ) = @_; + + _addHeader(); + + # not used yet: + #my $triangle_right = '►'; + #my $triangle_down = '▼'; + + my $id = $params->{'id'}; + if ( !defined $id || $id eq '' ) { + return ''; + } + my $idTag = $id . $twistyControlState if ($twistyControlState) || ''; + + my $defaultLink = + ( $twistyControlState eq 'show' ) ? $prefShowLink : $prefHideLink; + + # link="" takes precedence over showlink="" and hidelink="" + my $link = $params->{'link'}; + + if ( !defined $link ) { + + # if 'link' is not set, try 'showlink' / 'hidelink' + $link = $params->{ $twistyControlState . 'link' }; + } + if ( !defined $link ) { + $link = $defaultLink || ''; + } + my $linkClass = $params->{'linkclass'} ? " $params->{'linkclass'}" : ''; + my $img = + $params->{ $twistyControlState . 'img' } + || $params->{'img'} + || ''; + my $imgright = + $params->{ $twistyControlState . 'imgright' } + || $params->{'imgright'} + || ''; + my $imgleft = + $params->{ $twistyControlState . 'imgleft' } + || $params->{'imgleft'} + || ''; + $img =~ s/['\"]//go; + $imgright =~ s/['\"]//go; + $imgleft =~ s/['\"]//go; + my $imgTag = + ( $img ne '' ) ? '' : ''; + my $imgRightTag = + ( $imgright ne '' ) + ? '' + : ''; + my $imgLeftTag = + ( $imgleft ne '' ) + ? '' + : ''; + + my $imgLinkTag = + '' + . $imgLeftTag + . '' + . $link + . '' + . $imgTag + . $imgRightTag . ''; + + my $isTrigger = 1; + my $props = ''; + + if ( $idTag && $params ) { + my $cookieState = _readCookie( $session, $idTag ); + my @propList = + _createHtmlProperties( $twistyControlState, $idTag, undef, $params, + $isTrigger, $cookieState ); + $props = @propList ? " " . join( " ", @propList ) : ''; + } + my $triggerTag = '' . $imgLinkTag . ''; + return $triggerTag; +} + +sub _createHtmlProperties { + my ( $twistyControlState, $idTag, $mode, $params, $isTrigger, $cookie ) = + @_; + my $class = $params->{'class'} || ''; + my $firststart = $params->{'firststart'} || ''; + my $firstStartHidden; + $firstStartHidden = 1 if ( $firststart eq 'hide' ); + my $firstStartShown; + $firstStartShown = 1 if ( $firststart eq 'show' ); + my $cookieShow; + $cookieShow = 1 if defined $cookie && $cookie == 1; + my $cookieHide; + $cookieHide = 1 if defined $cookie && $cookie == 0; + my $start = $params->{start} || ''; + my $startHidden; + $startHidden = 1 if ( $start eq 'hide' ); + my $startShown; + $startShown = 1 if ( $start eq 'show' ); + + _setDefaults(); + my $remember = $params->{'remember'} || $prefRemember; + my $noscript = $params->{'noscript'} || ''; + my $noscriptHide; + $noscriptHide = 1 if ( $noscript eq 'hide' ); + $mode ||= $prefMode; + + my @classList = (); + push( @classList, $class ) if $class && !$isTrigger; + push( @classList, 'twistyRememberSetting' ) if ( $remember eq 'on' ); + push( @classList, 'twistyForgetSetting' ) if ( $remember eq 'off' ); + push( @classList, 'twistyStartHide' ) if $startHidden; + push( @classList, 'twistyStartShow' ) if $startShown; + push( @classList, 'twistyFirstStartHide' ) if $firstStartHidden; + push( @classList, 'twistyFirstStartShow' ) if $firstStartShown; + + # Mimic the rules in twist.js, function _update() + my $state = ''; + $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $firstStartHidden; + $state = $TWISTYPLUGIN_CONTENT_SHOWN if $firstStartShown; + + # cookie setting may override firstStartHidden and firstStartShown + $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $cookieHide; + $state = $TWISTYPLUGIN_CONTENT_SHOWN if $cookieShow; + + # startHidden and startShown may override cookie + $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $startHidden; + $state = $TWISTYPLUGIN_CONTENT_SHOWN if $startShown; + + # assume trigger should be hidden + # unless explicitly said otherwise + my $shouldHideTrigger = 1; + if ($isTrigger) { + push( @classList, 'twistyTrigger foswikiUnvisited' ); + + if ( $state eq $TWISTYPLUGIN_CONTENT_SHOWN + && $twistyControlState eq 'hide' ) + { + $shouldHideTrigger = 0; + } + if ( $state eq $TWISTYPLUGIN_CONTENT_HIDDEN + && $twistyControlState eq 'show' ) + { + $shouldHideTrigger = 0; + } + push( @classList, 'twistyHidden' ) if $shouldHideTrigger; + } + + # assume content should be hidden + # unless explicitly said otherwise + my $shouldHideContent = 1; + if ( !$isTrigger ) { + push( @classList, 'twistyContent' ); + + if ( $state eq $TWISTYPLUGIN_CONTENT_SHOWN ) { + $shouldHideContent = 0; + } + push( @classList, 'foswikiMakeHidden' ) if $shouldHideContent; + } + + # deprecated + # should be done by Foswiki template scripts instead + if ( !$isTrigger && $noscriptHide ) { + if ( $mode eq 'div' ) { + push( @classList, 'foswikiMakeVisibleBlock' ); + } + else { + push( @classList, 'foswikiMakeVisibleInline' ); + } + } + + # let javascript know we have set the state already + push( @classList, 'twistyInited' . $state ); + + my @propList = (); + push( @propList, 'id="' . $idTag . '"' ); + my $classListString = join( " ", @classList ); + push( @propList, 'class="' . $classListString . '"' ); + return @propList; +} + +=begin TML + +Reads a setting from the FOSWIKIPREF cookie. +Returns: + * 1 if the cookie has been set (meaning: show content) + * 0 if the cookie is '0' (meaning: hide content) + * undef if no cookie has been set + +=cut + +sub _readCookie { + my ( $session, $idTag ) = @_; + + return '' if !$idTag; + + # which state do we use? + my $cgi = new CGI; + my $cookie = $cgi->cookie('FOSWIKIPREF'); + my $tag = $idTag; + $tag =~ s/^(.*)(hide|show|toggle)$/$1/go; + my $key = $TWISTYPLUGIN_COOKIE_PREFIX . $tag; + + return unless ( defined($key) && defined($cookie) ); + + my $value = ''; + if ( $cookie =~ m/\b$key\=(.+?)\b/gi ) { + $value = $1; + } + + return if $value eq ''; + return ( $value eq '1' ) ? 1 : 0; +} + +sub _wrapInButtonHtml { + my ( $text, $mode ) = @_; + return _wrapInContainerHideIfNoJavascripOpen($mode) . $text + . _wrapInContainerDivIfNoJavascripClose($mode); +} + +sub _wrapInContentHtmlOpen { + my ($mode) = @_; + return "<$mode class=\"twistyPlugin\">"; +} + +sub _wrapInContentHtmlClose { + my ($mode) = @_; + return ""; +} + +sub _wrapInContainerHideIfNoJavascripOpen { + my ($mode) = @_; + return '<' . $mode . ' class="twistyPlugin foswikiMakeVisibleInline">'; +} + +sub _wrapInContainerDivIfNoJavascripClose { + my ($mode) = @_; + return ''; +} + +1; diff --git a/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/DEPENDENCIES b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/DEPENDENCIES new file mode 100644 index 0000000000..ca35dc177b --- /dev/null +++ b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/DEPENDENCIES @@ -0,0 +1,3 @@ +Foswiki::Contrib::BehaviourContrib,>=0,perl,Required if using default Foswiki twisties. +TWiki::Plugins::JQueryPlugin,>=0.5,perl,Required if using jquery twisties. +TWiki::Plugins::DojoToolkitContrib,>=0,perl,Required if using dojo twisties. diff --git a/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/MANIFEST b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/MANIFEST new file mode 100644 index 0000000000..512cd63e60 --- /dev/null +++ b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/MANIFEST @@ -0,0 +1,11 @@ +data/System/TwistyPlugin.txt 0644 +lib/Foswiki/Plugins/TwistyPlugin.pm 0444 +pub/System/TwistyPlugin/twisty.js 0644 +pub/System/TwistyPlugin/twisty.css 0644 +pub/System/TwistyPlugin/twisty.dojo.js 0644 +pub/System/TwistyPlugin/twisty.jquery.css 0644 +pub/System/TwistyPlugin/twisty.jquery.js 0644 +templates/twistyplugin.tmpl 0444 +templates/twistyplugin.dojo.tmpl 0444 Template for DojoToolkitContrib twisties +templates/twistyplugin.jquery.tmpl 0444 Template for JQueryPlugin twisties +templates/twistyplugin.pattern.tmpl 0444 Template for default twisties with PatternSkin \ No newline at end of file diff --git a/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/build.pl b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/build.pl new file mode 100755 index 0000000000..3ab0fce719 --- /dev/null +++ b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin/build.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl -w +# +# Build for TwistyPlugin +# +BEGIN { + foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) { + unshift @INC, $pc; + } +} + +use Foswiki::Contrib::Build; + +# Create the build object +$build = new Foswiki::Contrib::Build( 'TwistyPlugin' ); + +# Build the target on the command line, or the default target +$build->build($build->{target}); + diff --git a/TwistyPlugin/pub/System/TwistyPlugin/twisty.css b/TwistyPlugin/pub/System/TwistyPlugin/twisty.css new file mode 100644 index 0000000000..ae9ad535cf --- /dev/null +++ b/TwistyPlugin/pub/System/TwistyPlugin/twisty.css @@ -0,0 +1,20 @@ +.twistyHidden { display:none; } +.twistyMakeHidden {} /* reserved */ +.twistyMakeVisible { display:none; } + +.twistyTrigger {} +.twistyContent {} +.twistyPlaceholder { /* color to be implemented by skin */ } +.twistyRememberSetting { /* behavior class */ } +.twistyForgetSetting { /* behavior class */ } +.twistyStartHide { /* behavior class */ } +.twistyStartShow { /* behavior class */ } +.twistyInited1 { /* behavior class: state is set to shown */ } +.twistyInited0 { /* behavior class: state is set to hidden */ } + +/* These styles are available in Foswiki, but provided here for older TWiki versions: */ +.foswikiMakeVisible, +.foswikiMakeVisibleInline, +.foswikiMakeVisibleBlock { + display:none; /* will be made visible with javascript */ +} \ No newline at end of file diff --git a/TwistyPlugin/pub/System/TwistyPlugin/twisty.dojo.js b/TwistyPlugin/pub/System/TwistyPlugin/twisty.dojo.js new file mode 100644 index 0000000000..b2361c7a00 --- /dev/null +++ b/TwistyPlugin/pub/System/TwistyPlugin/twisty.dojo.js @@ -0,0 +1,266 @@ +/* +To compress this file you can use Dojo ShrinkSafe compressor at +http://alex.dojotoolkit.org/shrinksafe/ +*/ + +/** +Singleton class. +*/ +var foswiki; if (!foswiki) foswiki = {}; +foswiki.TwistyPlugin = new function () { + + var self = this; + + /** + Retrieves the name of the twisty from an HTML element id. For example 'demotoggle' will return 'demo'. + @param inId : (String) HTML element id + @return String + @privileged + */ + this._getName = function (e) { + var re = new RegExp("(.*)(hide|show|toggle)", "g"); + var inId = dojo.attr(e, 'id'); + var m = re.exec(inId); + var name = (m && m[1]) ? m[1] : ""; + return name; + } + + /** + Retrieves the type of the twisty from an HTML element id. For example 'demotoggle' will return 'toggle'. + @param inId : (String) HTML element id + @return String + @privileged + */ + this._getType = function (inId) { + var re = new RegExp("(.*)(hide|show|toggle)", "g"); + var m = re.exec(inId); + var type = (m && m[2]) ? m[2] : ""; + return type; + } + + /** + Toggles the collapsed state. Calls _update(). + @privileged + */ + this._toggleTwisty = function (ref) { + if (!ref) return; + ref.state = (ref.state == foswiki.TwistyPlugin.CONTENT_HIDDEN) ? foswiki.TwistyPlugin.CONTENT_SHOWN : foswiki.TwistyPlugin.CONTENT_HIDDEN; + self._update(ref, true); + } + + /** + Updates the states of UI trinity 'show', 'hide' and 'content'. + Saves new state in a cookie if one of the elements has CSS class 'twistyRememberSetting'. + @param ref : (Object) foswiki.TwistyPlugin.Storage object + @privileged + */ + this._update = function (ref, inMaySave) { + var showControl = ref.show; + + var hideControl = ref.hide; + + var contentElem = ref.toggle; + + //can implement Micha's animation using + //dojo.anim("thinger", { width: 500, height: 500 }, 500); + + + if (ref.state == foswiki.TwistyPlugin.CONTENT_SHOWN) { + + // show content + + dojo.addClass(showControl, 'twistyHidden'); // hide 'show' + + dojo.removeClass(hideControl, 'twistyHidden'); // show 'hide' + + dojo.removeClass(contentElem, 'twistyHidden'); // show content + + } else { + + // hide content + + dojo.removeClass(showControl, 'twistyHidden'); // show 'show' + + dojo.addClass(hideControl, 'twistyHidden'); // hide 'hide' + + dojo.addClass(contentElem, 'twistyHidden'); // hide content + + } + + if (inMaySave && ref.saveSetting) { + + foswiki.Pref.setPref(foswiki.TwistyPlugin.COOKIE_PREFIX + ref.name, ref.state); + + } + + if (ref.clearSetting) { + + foswiki.Pref.setPref(foswiki.TwistyPlugin.COOKIE_PREFIX + ref.name, ""); + + } + } + + /** + Stores a twisty HTML element (either show control, hide control or content 'toggle'). + @param e : (Object) HTMLElement + @privileged + */ + this._register = function (e) { + if (!e) return; + var name = self._getName(e); + var ref = self._storage[name]; + if (!ref) { + ref = new foswiki.TwistyPlugin.Storage(); + } + var classValue = dojo.attr(e, 'class'); //TODO: replace with dojo.hasClass + ref.saveSetting = dojo.hasClass(e, 'twistyRememberSetting'); + ref.clearSetting = dojo.hasClass(e, 'twistyForgetSetting'); + ref.startShown = dojo.hasClass(e, 'twistyStartShow'); + ref.startHidden = dojo.hasClass(e, 'twistyStartHide'); + ref.firstStartShown = dojo.hasClass(e, 'twistyFirstStartShow'); + ref.firstStartHidden = dojo.hasClass(e, 'twistyFirstStartHide'); + + ref.name = name; + var type = self._getType(e.id); + ref[type] = e; + self._storage[name] = ref; + switch (type) { + case 'show': // fall through + case 'hide': + e.onclick = function() { + self._toggleTwisty(ref); + return false; + } + break; + } + return ref; + } + + /** + Key-value set of foswiki.TwistyPlugin.Storage objects. The value is accessed by twisty id identifier name. + @example var ref = self._storage["demo"]; + @privileged + */ + this._storage = {}; +}; + +/** +Public constants. +*/ +foswiki.TwistyPlugin.CONTENT_HIDDEN = 0; +foswiki.TwistyPlugin.CONTENT_SHOWN = 1; +foswiki.TwistyPlugin.COOKIE_PREFIX = "TwistyPlugin_"; + +/** +The cached full Foswiki preference cookie string so the data has to be read only once during init. +*/ +foswiki.TwistyPlugin.prefList; + +/** +Initializes a twisty HTML element (either show control, hide control or content 'toggle') by registering and setting the visible state. +Calls _register() and _update(). +@public +@param inId : (String) id of HTMLElement +@return The stored foswiki.TwistyPlugin.Storage object. +*/ +foswiki.TwistyPlugin.init = function(e) { + if (!e) return; + + // check if already inited + var name = this._getName(e); + var ref = this._storage[name]; + if (ref && ref.show && ref.hide && ref.toggle) return ref; + + // else register + ref = this._register(e); + + //foswiki.CSS.replaceClass(e, "twistyMakeHidden", "twistyHidden"); + + dojo.removeClass(e, "foswikiMakeVisible"); + + dojo.removeClass(e, "foswikiMakeVisibleBlock"); + + dojo.removeClass(e, "foswikiMakeVisibleInline"); + + dojo.removeClass(e, "foswikiMakeHidden"); + + + + if (ref.show && ref.hide && ref.toggle) { + // all Twisty elements present + + if (dojo.hasClass(e, 'twistyInited1')) { + ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN + this._update(ref, false); + return ref; + } + if (dojo.hasClass(e, 'twistyInited0')) { + ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN + this._update(ref, false); + return ref; + } + + if (foswiki.TwistyPlugin.prefList == null) { + // cache complete cookie string + foswiki.TwistyPlugin.prefList = foswiki.Pref.getPrefList(); + } + var cookie = foswiki.Pref.getPrefValueFromPrefList(foswiki.TwistyPlugin.COOKIE_PREFIX + ref.name, foswiki.TwistyPlugin.prefList); + if (ref.firstStartHidden) ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; + if (ref.firstStartShown) ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN; + // cookie setting may override firstStartHidden and firstStartShown + if (cookie && cookie == "0") ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; + if (cookie && cookie == "1") ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN; + // startHidden and startShown may override cookie + if (ref.startHidden) ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; + if (ref.startShown) ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN; + + this._update(ref, false); + } + return ref; +} + +foswiki.TwistyPlugin.toggleAll = function(inState) { + var i; + for (var i in this._storage) { + var e = this._storage[i]; + e.state = inState; + this._update(e, true); + } +} +foswiki.TwistyPlugin.toggleAll_Show = function() { + foswiki.TwistyPlugin.toggleAll(foswiki.TwistyPlugin.CONTENT_SHOWN); +} +foswiki.TwistyPlugin.toggleAll_Hide = function() { + foswiki.TwistyPlugin.toggleAll(foswiki.TwistyPlugin.CONTENT_HIDDEN); +} + +/** +Storage container for properties of a twisty HTML element: show control, hide control or toggle content. +*/ +foswiki.TwistyPlugin.Storage = function () { + this.name; // String + this.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; // Number + this.hide; // HTMLElement + this.show; // HTMLElement + this.toggle; // HTMLElement (content element) + this.saveSetting = false; // Boolean; default not saved + this.clearSetting = false; // Boolean; default not cleared + this.startShown; // Boolean + this.startHidden; // Boolean + this.firstStartShown; // Boolean + this.firstStartHidden; // Boolean +} + +/** + * dojo init + */ +foswiki.TwistyPlugin.onLoad = function() { + dojo.query(".twistyTrigger").forEach("foswiki.TwistyPlugin.init(item);"); + dojo.query(".twistyContent").forEach("foswiki.TwistyPlugin.init(item);"); + + dojo.query(".twistyExpandAll").onclick(foswiki.TwistyPlugin.toggleAll_Show); + dojo.query(".twistyCollapseAll").onclick(foswiki.TwistyPlugin.toggleAll_Hide); +} + +dojo.addOnLoad(foswiki.TwistyPlugin.onLoad); + diff --git a/TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.css b/TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.css new file mode 100644 index 0000000000..ef63c8ce0b --- /dev/null +++ b/TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.css @@ -0,0 +1,20 @@ +.twistyHidden { display:none; } +.twistyMakeHidden {} /* reserved */ +.twistyMakeVisible { display:none; } + +.twistyTrigger {} +span.twistyContent {} +.twistyPlaceholder { /* color to be implemented by skin */ } +.twistyRememberSetting { /* behavior class */ } +.twistyForgetSetting { /* behavior class */ } +.twistyStartHide { /* behavior class */ } +.twistyStartShow { /* behavior class */ } +.twistyInited1 { /* behavior class: state is set to shown */ } +.twistyInited0 { /* behavior class: state is set to hidden */ } + +/* These styles are available in Foswiki, but provided here for older TWiki versions: */ +.foswikiMakeVisible, +.foswikiMakeVisibleInline, +.foswikiMakeVisibleBlock { + display:none; /* will be made visible with javascript */ +} \ No newline at end of file diff --git a/TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.js b/TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.js new file mode 100644 index 0000000000..727d00383b --- /dev/null +++ b/TwistyPlugin/pub/System/TwistyPlugin/twisty.jquery.js @@ -0,0 +1,247 @@ +/* +To compress this file you can use Dojo ShrinkSafe compressor at +http://alex.dojotoolkit.org/shrinksafe/ +*/ + +/** +Singleton class. +*/ +var foswiki; if (!foswiki) foswiki = {}; +foswiki.JQueryTwistyPlugin = new function () { + + var self = this; + + /** + Retrieves the name of the twisty from an HTML element id. For example 'demotoggle' will return 'demo'. + @param inId : (String) HTML element id + @return String + @privileged + */ + this._getName = function (e) { + var re = new RegExp("(.*)(hide|show|toggle)", "g"); + var inId = $(e).attr('id'); + var m = re.exec(inId); + var name = (m && m[1]) ? m[1] : ""; + return name; + } + + /** + Retrieves the type of the twisty from an HTML element id. For example 'demotoggle' will return 'toggle'. + @param inId : (String) HTML element id + @return String + @privileged + */ + this._getType = function (inId) { + var re = new RegExp("(.*)(hide|show|toggle)", "g"); + var m = re.exec(inId); + var type = (m && m[2]) ? m[2] : ""; + return type; + } + + /** + Toggles the collapsed state. Calls _update(). + @privileged + */ + this._toggleTwisty = function (ref) { + if (!ref) return; + ref.state = (ref.state == foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN) ? foswiki.JQueryTwistyPlugin.CONTENT_SHOWN : foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN; + self._update(ref, true); + } + + /** + Updates the states of UI trinity 'show', 'hide' and 'content'. + Saves new state in a cookie if one of the elements has CSS class 'twistyRememberSetting'. + @param ref : (Object) foswiki.JQueryTwistyPlugin.Storage object + @privileged + */ + this._update = function (ref, inMaySave) { + var showControl = ref.show; + var hideControl = ref.hide; + var contentElem = ref.toggle; + if (ref.state == foswiki.JQueryTwistyPlugin.CONTENT_SHOWN) { + // show content + if (inMaySave) { + $(contentElem).slideDown({easing:'easeInOutQuad', duration:300}); + } else { + $(contentElem).show(); + + } + $(showControl).addClass("twistyHidden"); + $(hideControl).removeClass("twistyHidden"); + $(contentElem).removeClass("twistyHidden"); + } else { + // hide content + if (inMaySave) { + $(contentElem).slideUp({easing:'easeInOutQuad', duration:300}); + } else { + $(contentElem).hide(); + } + $(showControl).removeClass("twistyHidden"); + $(hideControl).addClass("twistyHidden"); + $(contentElem).addClass("twistyHidden"); + } + if (inMaySave && ref.saveSetting) { + foswiki.Pref.setPref(foswiki.JQueryTwistyPlugin.COOKIE_PREFIX + ref.name, ref.state); + } + if (ref.clearSetting) { + foswiki.Pref.setPref(foswiki.JQueryTwistyPlugin.COOKIE_PREFIX + ref.name, ""); + } + } + + /** + Stores a twisty HTML element (either show control, hide control or content 'toggle'). + @param e : (Object) HTMLElement + @privileged + */ + this._register = function (e) { + if (!e) return; + var name = self._getName(e); + var ref = self._storage[name]; + if (!ref) { + ref = new foswiki.JQueryTwistyPlugin.Storage(); + } + var classValue = $(e).attr('class'); + if (classValue.match(/\btwistyRememberSetting\b/)) + ref.saveSetting = true; + if (classValue.match(/\btwistyForgetSetting\b/)) + ref.clearSetting = true; + if (classValue.match(/\btwistyStartShow\b/)) + ref.startShown = true; + if (classValue.match(/\btwistyStartHide\b/)) + ref.startHidden = true; + if (classValue.match(/\btwistyFirstStartShow\b/)) + ref.firstStartShown = true; + if (classValue.match(/\btwistyFirstStartHide\b/)) + ref.firstStartHidden = true; + + ref.name = name; + var type = self._getType(e.id); + ref[type] = e; + self._storage[name] = ref; + switch (type) { + case 'show': // fall through + case 'hide': + e.onclick = function() { + self._toggleTwisty(ref); + return false; + } + break; + } + return ref; + } + + /** + Key-value set of foswiki.JQueryTwistyPlugin.Storage objects. The value is accessed by twisty id identifier name. + @example var ref = self._storage["demo"]; + @privileged + */ + this._storage = {}; +}; + +/** +Public constants. +*/ +foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN = 0; +foswiki.JQueryTwistyPlugin.CONTENT_SHOWN = 1; +foswiki.JQueryTwistyPlugin.COOKIE_PREFIX = "JQueryTwistyPlugin_"; + +/** +The cached full preference cookie string so the data has to be read only once during init. +*/ +foswiki.JQueryTwistyPlugin.prefList; + +/** +Initializes a twisty HTML element (either show control, hide control or content 'toggle') by registering and setting the visible state. +Calls _register() and _update(). +@public +@param inId : (String) id of HTMLElement +@return The stored foswiki.JQueryTwistyPlugin.Storage object. +*/ +foswiki.JQueryTwistyPlugin.init = function(e) { + if (!e) return; + + // check if already inited + var name = this._getName(e); + var ref = this._storage[name]; + if (ref && ref.show && ref.hide && ref.toggle) return ref; + + // else register + ref = this._register(e); + + if (ref.show && ref.hide && ref.toggle) { + // all Twisty elements present + + var classValue = $(e).attr('class'); + if (classValue.match(/\btwistyInited1\b/)) { + ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN + this._update(ref, false); + return ref; + } + if (classValue.match(/\btwistyInited0\b/)) { + ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN + this._update(ref, false); + return ref; + } + + if (foswiki.JQueryTwistyPlugin.prefList == null) { + // cache complete cookie string + foswiki.JQueryTwistyPlugin.prefList = foswiki.Pref.getPrefList(); + } + var cookie = foswiki.Pref.getPrefValueFromPrefList(foswiki.JQueryTwistyPlugin.COOKIE_PREFIX + ref.name, foswiki.JQueryTwistyPlugin.prefList); + if (ref.firstStartHidden) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN; + if (ref.firstStartShown) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN; + // cookie setting may override firstStartHidden and firstStartShown + if (cookie && cookie == "0") ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN; + if (cookie && cookie == "1") ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN; + // startHidden and startShown may override cookie + if (ref.startHidden) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN; + if (ref.startShown) ref.state = foswiki.JQueryTwistyPlugin.CONTENT_SHOWN; + + this._update(ref, false); + } + return ref; +} + +foswiki.JQueryTwistyPlugin.toggleAll = function(inState) { + var i; + for (var i in this._storage) { + var e = this._storage[i]; + e.state = inState; + this._update(e, true); + } +} + +/** +Storage container for properties of a twisty HTML element: show control, hide control or toggle content. +*/ +foswiki.JQueryTwistyPlugin.Storage = function () { + this.name; // String + this.state = foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN; // Number + this.hide; // HTMLElement + this.show; // HTMLElement + this.toggle; // HTMLElement (content element) + this.saveSetting = false; // Boolean; default not saved + this.clearSetting = false; // Boolean; default not cleared + this.startShown; // Boolean + this.startHidden; // Boolean + this.firstStartShown; // Boolean + this.firstStartHidden; // Boolean +} + +/** + * jquery init + */ +$(function() { + $(".twistyTrigger, .twistyContent"). + removeClass("twistyMakeHidden foswikiMakeHidden foswikiMakeVisible foswikiMakeVisibleBlock foswikiMakeVisibleInline"). + addClass("twistyHidden"). + each(function() { + foswiki.JQueryTwistyPlugin.init(this); + }); + $(".twistyExpandAll").click(function() { + foswiki.JQueryTwistyPlugin.toggleAll(foswiki.JQueryTwistyPlugin.CONTENT_SHOWN); + }); + $(".twistyCollapseAll").click(function() { + foswiki.JQueryTwistyPlugin.toggleAll(foswiki.JQueryTwistyPlugin.CONTENT_HIDDEN); + }); +}); diff --git a/TwistyPlugin/pub/System/TwistyPlugin/twisty.js b/TwistyPlugin/pub/System/TwistyPlugin/twisty.js new file mode 100644 index 0000000000..395eb781a0 --- /dev/null +++ b/TwistyPlugin/pub/System/TwistyPlugin/twisty.js @@ -0,0 +1,252 @@ +/* +To compress this file you can use Dojo ShrinkSafe compressor at +http://alex.dojotoolkit.org/shrinksafe/ +*/ + +/** +Singleton class. Requires behaviour.js from BehaviourContrib. +*/ +var foswiki; if (!foswiki) foswiki = {}; +foswiki.TwistyPlugin = new function () { + + var self = this; + + /** + Retrieves the name of the twisty from an HTML element id. For example 'demotoggle' will return 'demo'. + @param inId : (String) HTML element id + @return String + @privileged + */ + this._getName = function (inId) { + var re = new RegExp("(.*)(hide|show|toggle)", "g"); + var m = re.exec(inId); + var name = (m && m[1]) ? m[1] : ""; + return name; + } + + /** + Retrieves the type of the twisty from an HTML element id. For example 'demotoggle' will return 'toggle'. + @param inId : (String) HTML element id + @return String + @privileged + */ + this._getType = function (inId) { + var re = new RegExp("(.*)(hide|show|toggle)", "g"); + var m = re.exec(inId); + var type = (m && m[2]) ? m[2] : ""; + return type; + } + + /** + Toggles the collapsed state. Calls _update(). + @privileged + */ + this._toggleTwisty = function (ref) { + if (!ref) return; + ref.state = (ref.state == foswiki.TwistyPlugin.CONTENT_HIDDEN) ? foswiki.TwistyPlugin.CONTENT_SHOWN : foswiki.TwistyPlugin.CONTENT_HIDDEN; + self._update(ref, true); + } + + /** + Updates the states of UI trinity 'show', 'hide' and 'content'. + Saves new state in a cookie if one of the elements has CSS class 'twistyRememberSetting'. + @param ref : (Object) foswiki.TwistyPlugin.Storage object + @privileged + */ + this._update = function (ref, inMaySave) { + var showControl = ref.show; + var hideControl = ref.hide; + var contentElem = ref.toggle; + if (ref.state == foswiki.TwistyPlugin.CONTENT_SHOWN) { + // show content + foswiki.CSS.addClass(showControl, 'twistyHidden'); // hide 'show' + foswiki.CSS.removeClass(hideControl, 'twistyHidden'); // show 'hide' + foswiki.CSS.removeClass(contentElem, 'twistyHidden'); // show content + } else { + // hide content + foswiki.CSS.removeClass(showControl, 'twistyHidden'); // show 'show' + foswiki.CSS.addClass(hideControl, 'twistyHidden'); // hide 'hide' + foswiki.CSS.addClass(contentElem, 'twistyHidden'); // hide content + } + if (inMaySave && ref.saveSetting) { + foswiki.Pref.setPref(foswiki.TwistyPlugin.COOKIE_PREFIX + ref.name, ref.state); + } + if (ref.clearSetting) { + foswiki.Pref.setPref(foswiki.TwistyPlugin.COOKIE_PREFIX + ref.name, ""); + } + } + + /** + Stores a twisty HTML element (either show control, hide control or content 'toggle'). + @param e : (Object) HTMLElement + @privileged + */ + this._register = function (e) { + if (!e) return; + var name = self._getName(e.id); + var ref = self._storage[name]; + if (!ref) { + ref = new foswiki.TwistyPlugin.Storage(); + } + if (foswiki.CSS.hasClass(e, "twistyRememberSetting")) ref.saveSetting = true; + if (foswiki.CSS.hasClass(e, "twistyForgetSetting")) ref.clearSetting = true; + if (foswiki.CSS.hasClass(e, "twistyStartShow")) ref.startShown = true; + if (foswiki.CSS.hasClass(e, "twistyStartHide")) ref.startHidden = true; + if (foswiki.CSS.hasClass(e, "twistyFirstStartShow")) ref.firstStartShown = true; + if (foswiki.CSS.hasClass(e, "twistyFirstStartHide")) ref.firstStartHidden = true; + ref.name = name; + var type = self._getType(e.id); + ref[type] = e; + self._storage[name] = ref; + switch (type) { + case 'show': // fall through + case 'hide': + e.onclick = function() { + self._toggleTwisty(ref); + return false; + } + break; + } + return ref; + } + + /** + Key-value set of foswiki.TwistyPlugin.Storage objects. The value is accessed by twisty id identifier name. + @example var ref = self._storage["demo"]; + @privileged + */ + this._storage = {}; + + /** + UI element behaviour, in case no javascript 'trigger' tags are inserted in the html + @privileged + */ + this._UIbehaviour = { + /** + Show control, hide control + */ + '.twistyTrigger' : function(e) { + foswiki.TwistyPlugin.init(e.id); + e = null; + }, + /** + Content element + */ + '.twistyContent' : function(e) { + foswiki.TwistyPlugin.init(e.id); + e = null; + }, + /** + Content element + */ + '.twistyExpandAll' : function(e) { + e.onclick = function() { + foswiki.TwistyPlugin.toggleAll(foswiki.TwistyPlugin.CONTENT_SHOWN); + } + e = null; + }, + '.twistyCollapseAll' : function(e) { + e.onclick = function() { + foswiki.TwistyPlugin.toggleAll(foswiki.TwistyPlugin.CONTENT_HIDDEN); + } + e = null; + } + }; + Behaviour.register(this._UIbehaviour); +}; + +/** +Public constants. +*/ +foswiki.TwistyPlugin.CONTENT_HIDDEN = 0; +foswiki.TwistyPlugin.CONTENT_SHOWN = 1; +foswiki.TwistyPlugin.COOKIE_PREFIX = "TwistyPlugin_"; + +/** +The cached full Foswiki preference cookie string so the data has to be read only once during init. +*/ +foswiki.TwistyPlugin.prefList; + +/** +Initializes a twisty HTML element (either show control, hide control or content 'toggle') by registering and setting the visible state. +Calls _register() and _update(). +@public +@param inId : (String) id of HTMLElement +@return The stored foswiki.TwistyPlugin.Storage object. +*/ +foswiki.TwistyPlugin.init = function(inId) { + var e = document.getElementById(inId); + if (!e) return; + + // check if already inited + var name = this._getName(inId); + var ref = this._storage[name]; + if (ref && ref.show && ref.hide && ref.toggle) return ref; + + // else register + ref = this._register(e); + + foswiki.CSS.replaceClass(e, "twistyMakeHidden", "twistyHidden"); + foswiki.CSS.removeClass(e, "foswikiMakeVisible"); + foswiki.CSS.removeClass(e, "foswikiMakeVisibleBlock"); + foswiki.CSS.removeClass(e, "foswikiMakeVisibleInline"); + foswiki.CSS.removeClass(e, "foswikiMakeHidden"); + + if (ref.show && ref.hide && ref.toggle) { + // all Twisty elements present + + if (foswiki.CSS.hasClass(e, "twistyInited1")) { + ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN + this._update(ref, false); + return ref; + } + if (foswiki.CSS.hasClass(e, "twistyInited0")) { + ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN + this._update(ref, false); + return ref; + } + + if (foswiki.TwistyPlugin.prefList == null) { + // cache complete cookie string + foswiki.TwistyPlugin.prefList = foswiki.Pref.getPrefList(); + } + var cookie = foswiki.Pref.getPrefValueFromPrefList(foswiki.TwistyPlugin.COOKIE_PREFIX + ref.name, foswiki.TwistyPlugin.prefList); + if (ref.firstStartHidden) ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; + if (ref.firstStartShown) ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN; + // cookie setting may override firstStartHidden and firstStartShown + if (cookie && cookie == "0") ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; + if (cookie && cookie == "1") ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN; + // startHidden and startShown may override cookie + if (ref.startHidden) ref.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; + if (ref.startShown) ref.state = foswiki.TwistyPlugin.CONTENT_SHOWN; + + this._update(ref, false); + } + return ref; +} + +foswiki.TwistyPlugin.toggleAll = function(inState) { + var i; + for (var i in this._storage) { + var e = this._storage[i]; + e.state = inState; + this._update(e, true); + } +} + +/** +Storage container for properties of a twisty HTML element: show control, hide control or toggle content. +*/ +foswiki.TwistyPlugin.Storage = function () { + this.name; // String + this.state = foswiki.TwistyPlugin.CONTENT_HIDDEN; // Number + this.hide; // HTMLElement + this.show; // HTMLElement + this.toggle; // HTMLElement (content element) + this.saveSetting = false; // Boolean; default not saved + this.clearSetting = false; // Boolean; default not cleared + this.startShown; // Boolean + this.startHidden; // Boolean + this.firstStartShown; // Boolean + this.firstStartHidden; // Boolean +} \ No newline at end of file diff --git a/TwistyPlugin/templates/twistyplugin.dojo.tmpl b/TwistyPlugin/templates/twistyplugin.dojo.tmpl new file mode 100644 index 0000000000..cc791f186c --- /dev/null +++ b/TwistyPlugin/templates/twistyplugin.dojo.tmpl @@ -0,0 +1,15 @@ +%TMPL:INCLUDE{twistyplugin}% + +%TMPL:DEF{twisty:header}% + + + + + +%TMPL:END% \ No newline at end of file diff --git a/TwistyPlugin/templates/twistyplugin.jquery.tmpl b/TwistyPlugin/templates/twistyplugin.jquery.tmpl new file mode 100644 index 0000000000..7f635796b8 --- /dev/null +++ b/TwistyPlugin/templates/twistyplugin.jquery.tmpl @@ -0,0 +1,9 @@ +%TMPL:INCLUDE{twistyplugin}% + +%TMPL:DEF{twisty:header}% + + + +%TMPL:END% \ No newline at end of file diff --git a/TwistyPlugin/templates/twistyplugin.pattern.tmpl b/TwistyPlugin/templates/twistyplugin.pattern.tmpl new file mode 100644 index 0000000000..864a6ba1b5 --- /dev/null +++ b/TwistyPlugin/templates/twistyplugin.pattern.tmpl @@ -0,0 +1,10 @@ +%{ this is the default header for TwistyPlugin, using the Foswiki Javascript files }% + +%TMPL:DEF{twisty:header}% + + + + +%TMPL:END% diff --git a/TwistyPlugin/templates/twistyplugin.tmpl b/TwistyPlugin/templates/twistyplugin.tmpl new file mode 100644 index 0000000000..a494a0de65 --- /dev/null +++ b/TwistyPlugin/templates/twistyplugin.tmpl @@ -0,0 +1,12 @@ +%{ this is the default header for TwistyPlugin, using the Foswiki Javascript files }% + +%TMPL:DEF{twisty:header}% + + + + + + +%TMPL:END% diff --git a/TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginSuite.pm b/TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginSuite.pm new file mode 100644 index 0000000000..83acc327ed --- /dev/null +++ b/TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginSuite.pm @@ -0,0 +1,6 @@ +package TwistyPluginSuite; +use base 'Unit::TestSuite'; + +sub include_tests { return 'TwistyPluginTests' }; + +1; diff --git a/TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginTests.pm b/TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginTests.pm new file mode 100644 index 0000000000..b7335214cf --- /dev/null +++ b/TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginTests.pm @@ -0,0 +1,233 @@ +use strict; + +# tests for basic formatting + +package TwistyPluginTests; + +use base qw( FoswikiFnTestCase ); + +use Foswiki; +use Error qw( :try ); +my $TEST_WEB_NAME = 'TemporaryTwistyFormattingTestWeb'; + +sub new { + my $self = shift()->SUPER::new('TwistyFormatting', @_); + return $self; +} + +sub set_up { + my $this = shift; + + $this->SUPER::set_up(); +} + +# This formats the text up to immediately before s are removed, so we +# can see the nops. +sub do_test { + my ($this, $expected, $actual) = @_; + my $session = $this->{twiki}; + my $webName = $this->{test_web}; + my $topicName = $this->{test_topic}; + + $actual = $session->handleCommonTags( $actual, $webName, $topicName ); + $actual = $session->renderer->getRenderedVersion( $actual, $webName, $topicName ); + + $this->assert_html_equals($expected, $actual); +} + +sub test_TWISTY_mode_default { + my $this = shift; + + my $source = <More...Close content +EXPECTED + + $this->do_test($expected, $source); +} + +sub test_TWISTY_mode_div { + my $this = shift; + + my $source = <More...Close
div content
+EXPECTED + + $this->do_test($expected, $source); +} + +sub test_TWISTY_mode_default_with_id { + my $this = shift; + + my $source = <More...Close content +EXPECTED + + $this->do_test($expected, $source); +} + +sub test_TWISTYSHOW { + my $this = shift; + + my $source = <More... Close toggle content +EXPECTED + + $this->do_test($expected, $source); +} + +sub test_TWISTYBUTTON { + my $this = shift; + + my $source = <moremore content +EXPECTED + + $this->do_test($expected, $source); +} + +sub test_TWISTY_with_icons { + my $this = shift; + my $pubUrlTWikiWeb = Foswiki::Func::getPubUrlPath() . '/System'; + + my $source = <Show...Hide
+content with icons +
+EXPECTED3 + + # fix introduced linebreaks + $expected =~ s/src="\n/src="/go; + + $this->do_test($expected, $source); +} + +sub test_TWISTY_remember { + my $this = shift; + + my $source_off = <Show...Hide +my twisty content + +RESULT_OFF + + $this->do_test($result_off, $source_off); + + my $source = <Show...Hide +my twisty content + +EXPECTED + + $this->do_test($expected, $source); +} + +sub test_TWISTY_escaped_variable { + my $this = shift; + my $pubUrlTWikiWeb = Foswiki::Func::getPubUrlPath() . '/System'; + + my $source = <DONEDONE content +EXPECTED3 + + # fix introduced linebreaks + $expected =~ s/src="\n/src="/go; + + $this->do_test($expected, $source); +} + +sub test_TWISTY_param_linkclass { + my $this = shift; + + my $source = <openopen
+contents +
+EXPECTED + + $this->do_test($expected, $source); +} +1;