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 |
|
js/client_js.js | ||
---|---|---|
71 | 71 |
else if (action[0] == 'removeProp') $(action[1]).removeProp(action[2]); |
72 | 72 |
else if (action[0] == 'val') $(action[1]).val(action[2]); |
73 | 73 |
|
74 |
// Class attribute |
|
75 |
else if (action[0] == 'addClass') $(action[1]).addClass(action[2]); |
|
76 |
else if (action[0] == 'removeClass') $(action[1]).removeClass(action[2]); |
|
77 |
else if (action[0] == 'toggleClass') $(action[1]).toggleClass(action[2]); |
|
78 |
|
|
74 | 79 |
// Data storage |
75 | 80 |
else if (action[0] == 'data') $(action[1]).data(action[2], action[3]); |
76 | 81 |
else if (action[0] == 'removeData') $(action[1]).removeData(action[2]); |
Auch abrufbar als: Unified diff
ClientJS: jQuery-Funktionen addClass, removeClass, toggleClass; Utility-Funktion "action_if"; Doku