Skip to content

Commit

Permalink
Item9815: Random IDs make twisties forgetful
Browse files Browse the repository at this point in the history
Removed the randomness and restored the way that worked
Added documentation the best I could.
If you do not like it - improve it. This at least resolves the urgent bug that noone else took ownership of.


git-svn-id: http://svn.foswiki.org/branches/Release01x01@9706 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Oct 24, 2010
1 parent dd2b4bf commit f6d8fb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 9 additions & 1 deletion TwistyPlugin/data/System/TwistyPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<verbatim class="tml">
%TWISTY{
Expand Down Expand Up @@ -422,6 +422,13 @@ but use format tokens:
link="Count: ($percentCALC{$quot$dollarGET(infoCount)$quot}$percent)"
</verbatim>

---++ 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}%
Expand Down Expand Up @@ -475,6 +482,7 @@ You can override some default settings in the plugin by setting the following [[
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; |
| 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. |
Expand Down
2 changes: 1 addition & 1 deletion TwistyPlugin/data/System/VarTWISTY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This renders the button as well as the toggled content section contained within

Usage: =%<nop>TWISTY{ ... }% Toggable contents %<nop>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 |
Expand Down
11 changes: 5 additions & 6 deletions TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +41,7 @@ sub initPlugin {

$doneDefaults = 0;
$doneHeader = 0;
$twistyCount = 0;

_exportAnimationSpeed();

Expand Down Expand Up @@ -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

Expand All @@ -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 );
}
Expand Down

0 comments on commit f6d8fb5

Please sign in to comment.