Revision 5551a36b
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/ClientJS.pm | ||
---|---|---|
58 | 58 |
removeProp => 2, |
59 | 59 |
val => 2, |
60 | 60 |
|
61 |
# Class attribute |
|
62 |
addClass => 2, |
|
63 |
removeClass => 2, |
|
64 |
toggleClass => 2, |
|
65 |
|
|
61 | 66 |
# Data storage |
62 | 67 |
data => 3, |
63 | 68 |
removeData => 2, |
... | ... | |
123 | 128 |
return $self; |
124 | 129 |
} |
125 | 130 |
|
131 |
sub action_if { |
|
132 |
my ($self, $condition, @args) = @_; |
|
133 |
|
|
134 |
return $condition ? $self->action(@args) : $self; |
|
135 |
} |
|
136 |
|
|
126 | 137 |
sub init__actions { |
127 | 138 |
return []; |
128 | 139 |
} |
... | ... | |
338 | 349 |
|
339 | 350 |
The first variation is obviously better suited for chaining. |
340 | 351 |
|
341 |
Additional functions: |
|
352 |
=over 4 |
|
353 |
|
|
354 |
=item C<action $method, @args> |
|
355 |
|
|
356 |
Call the function with the name C<$method> on C<$self> with arguments |
|
357 |
C<@args>. Returns the return value of the actual function |
|
358 |
called. Useful for chaining (see above). |
|
359 |
|
|
360 |
=item C<action_if $condition, $method, @args> |
|
361 |
|
|
362 |
Call the function with the name C<$method> on C<$self> with arguments |
|
363 |
C<@args> if C<$condition> is trueish. Does nothing otherwise. |
|
364 |
|
|
365 |
Returns the return value of the actual function called if |
|
366 |
C<$condition> is trueish and C<$self> otherwise. Useful for chaining |
|
367 |
(see above). |
|
368 |
|
|
369 |
This function is equivalent to the following: |
|
370 |
|
|
371 |
if ($condition) { |
|
372 |
$obj->$method(@args); |
|
373 |
} |
|
374 |
|
|
375 |
But it is easier to integrate into a method call chain, e.g.: |
|
376 |
|
|
377 |
$js->html('#content', $html) |
|
378 |
->action_if($item->is_flagged, 'toggleClass', '#marker', 'flagged') |
|
379 |
->render($self); |
|
380 |
|
|
381 |
=back |
|
382 |
|
|
383 |
=head2 ADDITIONAL FUNCTIONS |
|
342 | 384 |
|
343 | 385 |
=over 4 |
344 | 386 |
|
Auch abrufbar als: Unified diff
ClientJS: jQuery-Funktionen addClass, removeClass, toggleClass; Utility-Funktion "action_if"; Doku