diff --git a/TwistyPlugin/data/System/TwistyPlugin.txt b/TwistyPlugin/data/System/TwistyPlugin.txt index 6707e1b504..a161deed25 100644 --- a/TwistyPlugin/data/System/TwistyPlugin.txt +++ b/TwistyPlugin/data/System/TwistyPlugin.txt @@ -162,7 +162,7 @@ my twisty content %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=. +*Note:* Twisty ids are generated automatically based on web and topic names and a counter that increments for each twisty. If you need control over exactly _which_ Twisty should be remembered, add the parameter =id=. Application developers creating e.g. Ajax applications where the fetched content contains a Twisty should always provide an ID. %TWISTY{ @@ -422,6 +422,13 @@ but use format tokens: link="Count: ($percentCALC{$quot$dollarGET(infoCount)$quot}$percent)" +---++ Generation of the twisty ID + +When you define the =id= parameter a twisty the actual ID is appended by a number that counts from 1 for each twisty to ensure that the ID is unique. + +If you do not define an =id=, the plugin autogenerates an ID based on web and topic names and a counter that counts from 1 for each twisty. + +In ajax application you may need to ensure that the ID is unique for each call. For this always define the id parameter in your application to ensure a unique id for each call. ---++ Syntax %INCLUDE{VarTWISTY}% @@ -475,6 +482,7 @@ You can override some default settings in the plugin by setting the following [[ | Version: | %$VERSION% | | Release: | %$RELEASE% | | Change History: |   | +| 24 Oct 2010 | 1.6.7 Foswikitask:Item9815: Changed random IDs back to predictable IDs to restore remember feature | | 11 Sep 2010 | 1.6.6 Foswikitask:Item9499: Recoded show/hide animation code for smooth twisties. | | 10 Sep 2010 | 1.6.5 Foswikitask:Item9515: Simplified code that shows/hides twisties. | | 05 Sep 2010 | 1.6.4 Foswikitask:Item9626: Put link class around link and image. | diff --git a/TwistyPlugin/data/System/VarTWISTY.txt b/TwistyPlugin/data/System/VarTWISTY.txt index fdae8d77ec..97ba7c6652 100644 --- a/TwistyPlugin/data/System/VarTWISTY.txt +++ b/TwistyPlugin/data/System/VarTWISTY.txt @@ -6,7 +6,7 @@ This renders the button as well as the toggled content section contained within Usage: =%TWISTY{ ... }% Toggable contents %ENDTWISTY%= | *Parameter* | *Value* | *Description* | *Remark* | - | =id= | Unique identifier | Used to link [[#VarTWISTYBUTTON][TWISTYBUTTON]] and [[#VarTWISTYTOGGLE][TWISTYTOGGLE]] | optional | + | =id= | Unique identifier | Used to link [[#VarTWISTYBUTTON][TWISTYBUTTON]] and [[#VarTWISTYTOGGLE][TWISTYTOGGLE]]. Application developers. | 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 | diff --git a/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm index d3bb61f41b..678d95c559 100644 --- a/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm +++ b/TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm @@ -14,12 +14,12 @@ use CGI (); use strict; use warnings; -use vars qw( @twistystack $doneHeader $doneDefaults +use vars qw( @twistystack $doneHeader $doneDefaults $twistyCount $prefMode $prefShowLink $prefHideLink $prefRemember); our $VERSION = '$Rev$'; -our $RELEASE = '1.6.6'; +our $RELEASE = '1.6.7'; our $SHORTDESCRIPTION = 'Twisty section Javascript library to open/close content dynamically'; our $NO_PREFS_IN_TOPIC = 1; @@ -41,6 +41,7 @@ sub initPlugin { $doneDefaults = 0; $doneHeader = 0; + $twistyCount = 0; _exportAnimationSpeed(); @@ -153,7 +154,7 @@ sub _TWISTYBUTTON { =pod -If no ID is passed, creates a new unique id based on web and topic. Adds a random number for cases the twisty is loaded through AJAX. +If no ID is passed, creates a new unique id based on web and topic. =cut @@ -164,10 +165,8 @@ sub _TWISTY { my $id = $params->{'id'}; if ( !defined $id || $id eq '' ) { $params->{'id'} = _createId( $params->{'id'}, $theWeb, $theTopic ); - - # randomize this id in case the twisty is loaded through AJAX - $params->{'id'} .= int( rand(10000) ) + 1; } + $params->{'id'} .= ++$twistyCount; return _TWISTYBUTTON( $session, $params, $theTopic, $theWeb ) . _TWISTYTOGGLE( $session, $params, $theTopic, $theWeb ); }