Filename | /var/www/foswiki11/lib/Foswiki/Plugins/TwistyPlugin.pm |
Statements | Executed 40 statements in 2.24ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.47ms | 1.65ms | BEGIN@12 | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 64µs | 350µs | initPlugin | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 17µs | 125µs | _exportAnimationSpeed | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 10µs | 10µs | BEGIN@11 | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 10µs | 29µs | BEGIN@20 | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 9µs | 64µs | BEGIN@17 | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 8µs | 20µs | BEGIN@14 | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 8µs | 13µs | BEGIN@15 | Foswiki::Plugins::TwistyPlugin::
1 | 1 | 1 | 5µs | 5µs | BEGIN@13 | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _ENDTWISTYTOGGLE | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _TWISTY | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _TWISTYBUTTON | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _TWISTYHIDE | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _TWISTYSHOW | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _TWISTYTOGGLE | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _addHeader | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _createHtmlProperties | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _createId | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _readCookie | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _setDefaults | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _twistyBtn | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _wrapInButtonHtml | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _wrapInContainerDivIfNoJavascripClose | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _wrapInContainerHideIfNoJavascripOpen | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _wrapInContentHtmlClose | Foswiki::Plugins::TwistyPlugin::
0 | 0 | 0 | 0s | 0s | _wrapInContentHtmlOpen | Foswiki::Plugins::TwistyPlugin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package TwistyPlugin | ||||
6 | |||||
7 | =cut | ||||
8 | |||||
9 | package Foswiki::Plugins::TwistyPlugin; | ||||
10 | |||||
11 | 2 | 26µs | 1 | 10µs | # spent 10µs within Foswiki::Plugins::TwistyPlugin::BEGIN@11 which was called:
# once (10µs+0s) by Foswiki::Plugin::BEGIN@2.36 at line 11 # spent 10µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@11 |
12 | 2 | 100µs | 1 | 1.65ms | # spent 1.65ms (1.47+177µs) within Foswiki::Plugins::TwistyPlugin::BEGIN@12 which was called:
# once (1.47ms+177µs) by Foswiki::Plugin::BEGIN@2.36 at line 12 # spent 1.65ms making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@12 |
13 | 2 | 22µs | 1 | 5µs | # spent 5µs within Foswiki::Plugins::TwistyPlugin::BEGIN@13 which was called:
# once (5µs+0s) by Foswiki::Plugin::BEGIN@2.36 at line 13 # spent 5µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@13 |
14 | 2 | 24µs | 2 | 32µs | # spent 20µs (8+12) within Foswiki::Plugins::TwistyPlugin::BEGIN@14 which was called:
# once (8µs+12µs) by Foswiki::Plugin::BEGIN@2.36 at line 14 # spent 20µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@14
# spent 12µs making 1 call to strict::import |
15 | 2 | 30µs | 2 | 18µs | # spent 13µs (8+5) within Foswiki::Plugins::TwistyPlugin::BEGIN@15 which was called:
# once (8µs+5µs) by Foswiki::Plugin::BEGIN@2.36 at line 15 # spent 13µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@15
# spent 5µs making 1 call to warnings::import |
16 | |||||
17 | 1 | 6µs | 1 | 56µs | # spent 64µs (9+56) within Foswiki::Plugins::TwistyPlugin::BEGIN@17 which was called:
# once (9µs+56µs) by Foswiki::Plugin::BEGIN@2.36 at line 18 # spent 56µs making 1 call to vars::import |
18 | 1 | 28µs | 1 | 64µs | $prefMode $prefShowLink $prefHideLink $prefRemember); # spent 64µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@17 |
19 | |||||
20 | 3 | 1.93ms | 3 | 94µs | # spent 29µs (10+19) within Foswiki::Plugins::TwistyPlugin::BEGIN@20 which was called:
# once (10µs+19µs) by Foswiki::Plugin::BEGIN@2.36 at line 20 # spent 47µs making 1 call to version::vxs::declare
# spent 29µs making 1 call to Foswiki::Plugins::TwistyPlugin::BEGIN@20
# spent 19µs making 1 call to version::import |
21 | 1 | 300ns | our $RELEASE = '1.6.18'; | ||
22 | 1 | 200ns | our $SHORTDESCRIPTION = | ||
23 | 'Twisty section Javascript library to open/close content dynamically'; | ||||
24 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
25 | |||||
26 | 1 | 400ns | my $TWISTYPLUGIN_COOKIE_PREFIX = "TwistyPlugin_"; | ||
27 | 1 | 100ns | my $TWISTYPLUGIN_CONTENT_HIDDEN = 0; | ||
28 | 1 | 100ns | my $TWISTYPLUGIN_CONTENT_SHOWN = 1; | ||
29 | |||||
30 | #there is no need to document this. | ||||
31 | # spent 350µs (64+286) within Foswiki::Plugins::TwistyPlugin::initPlugin which was called:
# once (64µs+286µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
32 | 1 | 2µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
33 | |||||
34 | # check for Plugins.pm versions | ||||
35 | 1 | 15µs | 1 | 9µs | if ( $Foswiki::Plugins::VERSION < 1.1 ) { # spent 9µs making 1 call to version::vxs::VCMP |
36 | Foswiki::Func::writeWarning( | ||||
37 | "Version mismatch between TwistyPlugin and Plugins.pm"); | ||||
38 | return 0; | ||||
39 | } | ||||
40 | |||||
41 | 1 | 2µs | $doneDefaults = 0; | ||
42 | 1 | 600ns | $doneHeader = 0; | ||
43 | 1 | 300ns | $twistyCount = 0; | ||
44 | |||||
45 | 1 | 3µs | 1 | 125µs | _exportAnimationSpeed(); # spent 125µs making 1 call to Foswiki::Plugins::TwistyPlugin::_exportAnimationSpeed |
46 | |||||
47 | 1 | 3µs | 1 | 19µs | Foswiki::Plugins::JQueryPlugin::registerPlugin( 'twisty', # spent 19µs making 1 call to Foswiki::Plugins::JQueryPlugin::registerPlugin |
48 | 'Foswiki::Plugins::TwistyPlugin::TWISTY' ); | ||||
49 | 1 | 4µs | 1 | 24µs | Foswiki::Func::registerTagHandler( 'TWISTYSHOW', \&_TWISTYSHOW ); # spent 24µs making 1 call to Foswiki::Func::registerTagHandler |
50 | 1 | 2µs | 1 | 18µs | Foswiki::Func::registerTagHandler( 'TWISTYHIDE', \&_TWISTYHIDE ); # spent 18µs making 1 call to Foswiki::Func::registerTagHandler |
51 | 1 | 4µs | 1 | 19µs | Foswiki::Func::registerTagHandler( 'TWISTYBUTTON', \&_TWISTYBUTTON ); # spent 19µs making 1 call to Foswiki::Func::registerTagHandler |
52 | 1 | 2µs | 1 | 18µs | Foswiki::Func::registerTagHandler( 'TWISTY', \&_TWISTY ); # spent 18µs making 1 call to Foswiki::Func::registerTagHandler |
53 | 1 | 4µs | 1 | 18µs | Foswiki::Func::registerTagHandler( 'ENDTWISTY', \&_ENDTWISTYTOGGLE ); # spent 18µs making 1 call to Foswiki::Func::registerTagHandler |
54 | 1 | 2µs | 1 | 18µs | Foswiki::Func::registerTagHandler( 'TWISTYTOGGLE', \&_TWISTYTOGGLE ); # spent 18µs making 1 call to Foswiki::Func::registerTagHandler |
55 | 1 | 1µs | 1 | 18µs | Foswiki::Func::registerTagHandler( 'ENDTWISTYTOGGLE', \&_ENDTWISTYTOGGLE ); # spent 18µs making 1 call to Foswiki::Func::registerTagHandler |
56 | |||||
57 | 1 | 6µs | return 1; | ||
58 | } | ||||
59 | |||||
60 | # spent 125µs (17+108) within Foswiki::Plugins::TwistyPlugin::_exportAnimationSpeed which was called:
# once (17µs+108µs) by Foswiki::Plugins::TwistyPlugin::initPlugin at line 45 | ||||
61 | |||||
62 | 1 | 4µs | 2 | 88µs | my $pref = # spent 56µs making 1 call to Foswiki::Func::getPluginPreferencesValue
# spent 31µs making 1 call to Foswiki::Func::getPreferencesValue |
63 | Foswiki::Func::getPreferencesValue('TWISTYANIMATIONSPEED') | ||||
64 | || Foswiki::Func::getPluginPreferencesValue('TWISTYANIMATIONSPEED') | ||||
65 | || '0'; | ||||
66 | |||||
67 | # add TWISTYANIMATIONSPEED to the html head so | ||||
68 | # that it may be used in the client JS with | ||||
69 | # foswiki.getPreference('TWISTYANIMATIONSPEED') | ||||
70 | 1 | 3µs | 1 | 21µs | Foswiki::Func::addToZone( "script", "TWISTYPLUGIN::META", # spent 21µs making 1 call to Foswiki::Func::addToZone |
71 | <<"HERE", "JQUERYPLUGIN::FOSWIKI::PREFERENCES" ); | ||||
72 | <script type='text/javascript'>jQuery.extend(foswiki.preferences, { TWISTYANIMATIONSPEED: '$pref' });</script> | ||||
73 | HERE | ||||
74 | |||||
75 | 1 | 5µs | return; | ||
76 | } | ||||
77 | |||||
78 | sub _setDefaults { | ||||
79 | return if $doneDefaults; | ||||
80 | $doneDefaults = 1; | ||||
81 | |||||
82 | $prefMode = | ||||
83 | Foswiki::Func::getPreferencesValue('TWISTYMODE') | ||||
84 | || Foswiki::Func::getPluginPreferencesValue('TWISTYMODE') | ||||
85 | || 'div'; | ||||
86 | $prefShowLink = | ||||
87 | Foswiki::Func::getPreferencesValue('TWISTYSHOWLINK') | ||||
88 | || Foswiki::Func::getPluginPreferencesValue('TWISTYSHOWLINK') | ||||
89 | || '%MAKETEXT{"More..."}%'; | ||||
90 | $prefHideLink = | ||||
91 | Foswiki::Func::getPreferencesValue('TWISTYHIDELINK') | ||||
92 | || Foswiki::Func::getPluginPreferencesValue('TWISTYHIDELINK') | ||||
93 | || '%MAKETEXT{"Close"}%'; | ||||
94 | $prefRemember = | ||||
95 | Foswiki::Func::getPreferencesValue('TWISTYREMEMBER') | ||||
96 | || Foswiki::Func::getPluginPreferencesValue('TWISTYREMEMBER') | ||||
97 | || ''; | ||||
98 | |||||
99 | return; | ||||
100 | } | ||||
101 | |||||
102 | sub _addHeader { | ||||
103 | return if $doneHeader; | ||||
104 | $doneHeader = 1; | ||||
105 | |||||
106 | if ( Foswiki::Func::getContext()->{JQueryPluginEnabled} ) { | ||||
107 | Foswiki::Plugins::JQueryPlugin::createPlugin('twisty'); | ||||
108 | } | ||||
109 | else { | ||||
110 | my $header; | ||||
111 | Foswiki::Func::loadTemplate('twistyplugin'); | ||||
112 | |||||
113 | $header = | ||||
114 | Foswiki::Func::expandTemplate("TwistyPlugin/twisty") | ||||
115 | . Foswiki::Func::expandTemplate("TwistyPlugin/twisty.css"); | ||||
116 | Foswiki::Func::expandCommonVariables($header); | ||||
117 | } | ||||
118 | |||||
119 | return; | ||||
120 | } | ||||
121 | |||||
122 | sub _TWISTYSHOW { | ||||
123 | my ( $session, $params, $theTopic, $theWeb ) = @_; | ||||
124 | _setDefaults(); | ||||
125 | |||||
126 | my $mode = $params->{'mode'} || $prefMode; | ||||
127 | my $btn = _twistyBtn( 'show', $session, $params, $theTopic, $theWeb ); | ||||
128 | return Foswiki::Func::decodeFormatTokens( | ||||
129 | _wrapInButtonHtml( $btn, $mode ) ); | ||||
130 | } | ||||
131 | |||||
132 | sub _TWISTYHIDE { | ||||
133 | my ( $session, $params, $theTopic, $theWeb ) = @_; | ||||
134 | _setDefaults(); | ||||
135 | my $mode = $params->{'mode'} || $prefMode; | ||||
136 | my $btn = _twistyBtn( 'hide', $session, $params, $theTopic, $theWeb ); | ||||
137 | return Foswiki::Func::decodeFormatTokens( | ||||
138 | _wrapInButtonHtml( $btn, $mode ) ); | ||||
139 | } | ||||
140 | |||||
141 | sub _TWISTYBUTTON { | ||||
142 | my ( $session, $params, $theTopic, $theWeb ) = @_; | ||||
143 | _setDefaults(); | ||||
144 | |||||
145 | my $mode = $params->{'mode'} || $prefMode; | ||||
146 | my $btnShow = _twistyBtn( 'show', $session, $params, $theTopic, $theWeb ); | ||||
147 | my $btnHide = _twistyBtn( 'hide', $session, $params, $theTopic, $theWeb ); | ||||
148 | my $prefix = $params->{'prefix'} || ''; | ||||
149 | my $suffix = $params->{'suffix'} || ''; | ||||
150 | my $btn = $prefix . $btnShow . $btnHide . $suffix; | ||||
151 | return Foswiki::Func::decodeFormatTokens( | ||||
152 | _wrapInButtonHtml( $btn, $mode ) ); | ||||
153 | } | ||||
154 | |||||
155 | =pod | ||||
156 | |||||
157 | If no ID is passed, creates a new unique id based on web and topic. | ||||
158 | |||||
159 | =cut | ||||
160 | |||||
161 | sub _TWISTY { | ||||
162 | my ( $session, $params, $theTopic, $theWeb ) = @_; | ||||
163 | |||||
164 | _addHeader(); | ||||
165 | $params->{'id'} = _createId( $params, $theWeb, $theTopic ); | ||||
166 | return _TWISTYBUTTON( $session, $params, $theTopic, $theWeb ) | ||||
167 | . _TWISTYTOGGLE( $session, $params, $theTopic, $theWeb ); | ||||
168 | } | ||||
169 | |||||
170 | sub _TWISTYTOGGLE { | ||||
171 | my ( $session, $params, $theTopic, $theWeb ) = @_; | ||||
172 | my $id = $params->{'id'}; | ||||
173 | if ( !defined $id || $id eq '' ) { | ||||
174 | return ''; | ||||
175 | } | ||||
176 | _setDefaults(); | ||||
177 | my $idTag = $id . 'toggle'; | ||||
178 | my $mode = $params->{'mode'} || $prefMode; | ||||
179 | push( @twistystack, { mode => $mode, id => $idTag } ); | ||||
180 | |||||
181 | my $isTrigger = 0; | ||||
182 | my $cookieState = _readCookie( $session, $idTag ); | ||||
183 | my @propList = | ||||
184 | _createHtmlProperties( undef, $idTag, $mode, $params, $isTrigger, | ||||
185 | $cookieState ); | ||||
186 | my $props = @propList ? " " . join( " ", @propList ) : ''; | ||||
187 | my $modeTag = '<' . $mode . $props . '>'; | ||||
188 | return Foswiki::Func::decodeFormatTokens( | ||||
189 | _wrapInContentHtmlOpen($mode) . $modeTag ); | ||||
190 | } | ||||
191 | |||||
192 | sub _ENDTWISTYTOGGLE { | ||||
193 | my ( $session, $params, $theTopic, $theWeb ) = @_; | ||||
194 | my $twisty = pop @twistystack; | ||||
195 | |||||
196 | return | ||||
197 | "<div class='foswikiAlert'>woops, ordering error: got an ENDTWISTY before seeing a TWISTY</div>" | ||||
198 | unless $twisty->{mode}; | ||||
199 | |||||
200 | my $modeTag = ( $twisty->{mode} ) ? '</' . $twisty->{mode} . '>' : ''; | ||||
201 | return $modeTag . _wrapInContentHtmlClose($twisty); | ||||
202 | } | ||||
203 | |||||
204 | sub _createId { | ||||
205 | my ( $params, $inWeb, $inTopic ) = @_; | ||||
206 | |||||
207 | my $id = $params->{'id'} || "twistyId$inWeb$inTopic"; | ||||
208 | $id =~ s/\//subweb/go; | ||||
209 | |||||
210 | # Ensure uniqueness, or at least try to | ||||
211 | my $remember = $params->{'remember'} || $prefRemember; | ||||
212 | if ( Foswiki::Func::isTrue($remember) ) { | ||||
213 | $id .= ++$twistyCount; # For remember | ||||
214 | } | ||||
215 | else { # 100 is the number of remembered cookies to avoid clashes | ||||
216 | $id .= int( rand(10000) ) + 100; # For AJAX | ||||
217 | } | ||||
218 | return $id; | ||||
219 | } | ||||
220 | |||||
221 | sub _twistyBtn { | ||||
222 | my ( $twistyControlState, $session, $params, $theTopic, $theWeb ) = @_; | ||||
223 | |||||
224 | _addHeader(); | ||||
225 | |||||
226 | # not used yet: | ||||
227 | #my $triangle_right = '►'; | ||||
228 | #my $triangle_down = '▼'; | ||||
229 | |||||
230 | my $id = $params->{'id'}; | ||||
231 | if ( !defined $id || $id eq '' ) { | ||||
232 | return ''; | ||||
233 | } | ||||
234 | my $idTag; | ||||
235 | if ($twistyControlState) { | ||||
236 | $idTag = $id . $twistyControlState; | ||||
237 | } | ||||
238 | else { | ||||
239 | $idTag = ''; | ||||
240 | } | ||||
241 | |||||
242 | my $defaultLink = | ||||
243 | ( $twistyControlState eq 'show' ) ? $prefShowLink : $prefHideLink; | ||||
244 | |||||
245 | # link="" takes precedence over showlink="" and hidelink="" | ||||
246 | my $link = $params->{'link'}; | ||||
247 | |||||
248 | if ( !defined $link ) { | ||||
249 | |||||
250 | # if 'link' is not set, try 'showlink' / 'hidelink' | ||||
251 | $link = $params->{ $twistyControlState . 'link' }; | ||||
252 | } | ||||
253 | if ( !defined $link ) { | ||||
254 | $link = $defaultLink || ''; | ||||
255 | } | ||||
256 | my $img = | ||||
257 | $params->{ $twistyControlState . 'img' } | ||||
258 | || $params->{'img'} | ||||
259 | || ''; | ||||
260 | my $imgright = | ||||
261 | $params->{ $twistyControlState . 'imgright' } | ||||
262 | || $params->{'imgright'} | ||||
263 | || ''; | ||||
264 | my $imgleft = | ||||
265 | $params->{ $twistyControlState . 'imgleft' } | ||||
266 | || $params->{'imgleft'} | ||||
267 | || ''; | ||||
268 | $img =~ s/['\"]//go; | ||||
269 | $imgright =~ s/['\"]//go; | ||||
270 | $imgleft =~ s/['\"]//go; | ||||
271 | my $imgTag = | ||||
272 | ( $img ne '' ) ? '<img src="' . $img . '" border="0" alt="" />' : ''; | ||||
273 | my $imgRightTag = | ||||
274 | ( $imgright ne '' ) | ||||
275 | ? '<img src="' . $imgright . '" border="0" alt="" />' | ||||
276 | : ''; | ||||
277 | my $imgLeftTag = | ||||
278 | ( $imgleft ne '' ) | ||||
279 | ? '<img src="' . $imgleft . '" border="0" alt="" />' | ||||
280 | : ''; | ||||
281 | |||||
282 | my @linkClasses; | ||||
283 | push( @linkClasses, $params->{'linkclass'} ) if $params->{'linkclass'}; | ||||
284 | |||||
285 | my $imgLinkTag = CGI::a( | ||||
286 | { | ||||
287 | href => '#', | ||||
288 | class => join( ' ', @linkClasses ) | ||||
289 | }, | ||||
290 | $imgLeftTag | ||||
291 | . CGI::span( { class => 'foswikiLinkLabel foswikiUnvisited' }, $link ) | ||||
292 | . $imgTag | ||||
293 | . $imgRightTag | ||||
294 | ); | ||||
295 | |||||
296 | my $isTrigger = 1; | ||||
297 | my $props = ''; | ||||
298 | |||||
299 | if ( $idTag && $params ) { | ||||
300 | my $cookieState = _readCookie( $session, $idTag ); | ||||
301 | my @propList = | ||||
302 | _createHtmlProperties( $twistyControlState, $idTag, undef, $params, | ||||
303 | $isTrigger, $cookieState ); | ||||
304 | $props = @propList ? " " . join( " ", @propList ) : ''; | ||||
305 | } | ||||
306 | my $triggerTag = '<span' . $props . '>' . $imgLinkTag . '</span>'; | ||||
307 | return $triggerTag; | ||||
308 | } | ||||
309 | |||||
310 | sub _createHtmlProperties { | ||||
311 | my ( $twistyControlState, $idTag, $mode, $params, $isTrigger, $cookie ) = | ||||
312 | @_; | ||||
313 | my $class = $params->{'class'} || ''; | ||||
314 | my $firststart = $params->{'firststart'} || ''; | ||||
315 | my $firstStartHidden; | ||||
316 | $firstStartHidden = 1 if ( $firststart eq 'hide' ); | ||||
317 | my $firstStartShown; | ||||
318 | $firstStartShown = 1 if ( $firststart eq 'show' ); | ||||
319 | my $cookieShow; | ||||
320 | $cookieShow = 1 if defined $cookie && $cookie == 1; | ||||
321 | my $cookieHide; | ||||
322 | $cookieHide = 1 if defined $cookie && $cookie == 0; | ||||
323 | my $start = $params->{start} || ''; | ||||
324 | my $startHidden; | ||||
325 | $startHidden = 1 if ( $start eq 'hide' ); | ||||
326 | my $startShown; | ||||
327 | $startShown = 1 if ( $start eq 'show' ); | ||||
328 | my @propList = (); | ||||
329 | |||||
330 | _setDefaults(); | ||||
331 | my $remember = $params->{'remember'} || $prefRemember; | ||||
332 | my $noscript = $params->{'noscript'} || ''; | ||||
333 | my $noscriptHide = ( $noscript eq 'hide' ) ? 1 : 0; | ||||
334 | $mode ||= $prefMode; | ||||
335 | |||||
336 | my @classList = (); | ||||
337 | my @styleList = (); | ||||
338 | push( @classList, $class ) if $class && !$isTrigger; | ||||
339 | push( @classList, 'twistyRememberSetting' ) | ||||
340 | if Foswiki::Func::isTrue($remember); | ||||
341 | push( @classList, 'twistyForgetSetting' ) if $remember eq 'off'; | ||||
342 | push( @classList, 'twistyStartHide' ) if $startHidden; | ||||
343 | push( @classList, 'twistyStartShow' ) if $startShown; | ||||
344 | push( @classList, 'twistyFirstStartHide' ) if $firstStartHidden; | ||||
345 | push( @classList, 'twistyFirstStartShow' ) if $firstStartShown; | ||||
346 | |||||
347 | # Mimic the rules in twist.js, function _update() | ||||
348 | my $state = ''; | ||||
349 | $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $firstStartHidden; | ||||
350 | $state = $TWISTYPLUGIN_CONTENT_SHOWN if $firstStartShown; | ||||
351 | |||||
352 | # cookie setting may override firstStartHidden and firstStartShown | ||||
353 | $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $cookieHide; | ||||
354 | $state = $TWISTYPLUGIN_CONTENT_SHOWN if $cookieShow; | ||||
355 | |||||
356 | # startHidden and startShown may override cookie | ||||
357 | $state = $TWISTYPLUGIN_CONTENT_HIDDEN if $startHidden; | ||||
358 | $state = $TWISTYPLUGIN_CONTENT_SHOWN if $startShown; | ||||
359 | |||||
360 | # assume trigger should be hidden | ||||
361 | # unless explicitly said otherwise | ||||
362 | my $shouldHideTrigger = 1; | ||||
363 | if ($isTrigger) { | ||||
364 | push( @classList, 'twistyTrigger foswikiUnvisited' ); | ||||
365 | |||||
366 | if ( $state eq $TWISTYPLUGIN_CONTENT_SHOWN | ||||
367 | && $twistyControlState eq 'hide' ) | ||||
368 | { | ||||
369 | $shouldHideTrigger = 0; | ||||
370 | } | ||||
371 | if ( $state eq $TWISTYPLUGIN_CONTENT_HIDDEN | ||||
372 | && $twistyControlState eq 'show' ) | ||||
373 | { | ||||
374 | $shouldHideTrigger = 0; | ||||
375 | } | ||||
376 | push( @styleList, 'display:none' ) if $shouldHideTrigger; | ||||
377 | } | ||||
378 | |||||
379 | # assume content should be hidden | ||||
380 | # unless explicitly said otherwise | ||||
381 | if ( !$isTrigger ) { | ||||
382 | push( @classList, 'twistyContent' ); | ||||
383 | } | ||||
384 | |||||
385 | # deprecated | ||||
386 | # should be done by Foswiki template scripts instead | ||||
387 | if ( !$isTrigger && $noscriptHide ) { | ||||
388 | push( @classList, 'foswikiMakeVisible' ); | ||||
389 | } | ||||
390 | |||||
391 | # let javascript know we have set the state already | ||||
392 | push( @classList, 'twistyInited' . $state ); | ||||
393 | |||||
394 | push( @propList, 'id="' . $idTag . '"' ); | ||||
395 | |||||
396 | my $styleListString = join( ", ", @styleList ); | ||||
397 | push( @propList, 'style="' . $styleListString . '"' ); | ||||
398 | |||||
399 | my $classListString = join( " ", @classList ); | ||||
400 | push( @propList, 'class="' . $classListString . '"' ); | ||||
401 | |||||
402 | return @propList; | ||||
403 | } | ||||
404 | |||||
405 | =begin TML | ||||
406 | |||||
407 | Reads a setting from the FOSWIKIPREF cookie. | ||||
408 | Returns: | ||||
409 | * 1 if the cookie has been set (meaning: show content) | ||||
410 | * 0 if the cookie is '0' (meaning: hide content) | ||||
411 | * undef if no cookie has been set | ||||
412 | |||||
413 | =cut | ||||
414 | |||||
415 | sub _readCookie { | ||||
416 | my ( $session, $idTag ) = @_; | ||||
417 | |||||
418 | return '' if !$idTag; | ||||
419 | |||||
420 | # which state do we use? | ||||
421 | my $cgi = CGI->new(); | ||||
422 | my $cookie = $cgi->cookie('FOSWIKIPREF'); | ||||
423 | my $tag = $idTag; | ||||
424 | $tag =~ s/^(.*)(hide|show|toggle)$/$1/go; | ||||
425 | my $key = $TWISTYPLUGIN_COOKIE_PREFIX . $tag; | ||||
426 | |||||
427 | return unless ( defined($key) && defined($cookie) ); | ||||
428 | |||||
429 | my $value = ''; | ||||
430 | if ( $cookie =~ m/\b\Q$key=\E(.+?)\b/gi ) { | ||||
431 | $value = $1; | ||||
432 | } | ||||
433 | |||||
434 | return if $value eq ''; | ||||
435 | return ( $value eq '1' ) ? 1 : 0; | ||||
436 | } | ||||
437 | |||||
438 | sub _wrapInButtonHtml { | ||||
439 | my ( $text, $mode ) = @_; | ||||
440 | return _wrapInContainerHideIfNoJavascripOpen($mode) . $text | ||||
441 | . _wrapInContainerDivIfNoJavascripClose($mode); | ||||
442 | } | ||||
443 | |||||
444 | sub _wrapInContentHtmlOpen { | ||||
445 | my ($mode) = @_; | ||||
446 | return "<$mode class=\"twistyPlugin\">"; | ||||
447 | } | ||||
448 | |||||
449 | sub _wrapInContentHtmlClose { | ||||
450 | my ($twisty) = @_; | ||||
451 | my $closeTag = "</$twisty->{mode}>"; | ||||
452 | |||||
453 | return $closeTag; | ||||
454 | } | ||||
455 | |||||
456 | sub _wrapInContainerHideIfNoJavascripOpen { | ||||
457 | my ($mode) = @_; | ||||
458 | |||||
459 | return '<' . $mode . ' class="twistyPlugin foswikiMakeVisible">'; | ||||
460 | } | ||||
461 | |||||
462 | sub _wrapInContainerDivIfNoJavascripClose { | ||||
463 | my ($mode) = @_; | ||||
464 | |||||
465 | return '</' . $mode . '>'; | ||||
466 | } | ||||
467 | |||||
468 | 1 | 5µs | 1; | ||
469 | __END__ |