removeProp => 2,
val => 2,
+ # Class attribute
+ addClass => 2,
+ removeClass => 2,
+ toggleClass => 2,
+
# Data storage
data => 3,
removeData => 2,
return $self;
}
+sub action_if {
+ my ($self, $condition, @args) = @_;
+
+ return $condition ? $self->action(@args) : $self;
+}
+
sub init__actions {
return [];
}
The first variation is obviously better suited for chaining.
-Additional functions:
+=over 4
+
+=item C<action $method, @args>
+
+Call the function with the name C<$method> on C<$self> with arguments
+C<@args>. Returns the return value of the actual function
+called. Useful for chaining (see above).
+
+=item C<action_if $condition, $method, @args>
+
+Call the function with the name C<$method> on C<$self> with arguments
+C<@args> if C<$condition> is trueish. Does nothing otherwise.
+
+Returns the return value of the actual function called if
+C<$condition> is trueish and C<$self> otherwise. Useful for chaining
+(see above).
+
+This function is equivalent to the following:
+
+ if ($condition) {
+ $obj->$method(@args);
+ }
+
+But it is easier to integrate into a method call chain, e.g.:
+
+ $js->html('#content', $html)
+ ->action_if($item->is_flagged, 'toggleClass', '#marker', 'flagged')
+ ->render($self);
+
+=back
+
+=head2 ADDITIONAL FUNCTIONS
=over 4
else if (action[0] == 'removeProp') $(action[1]).removeProp(action[2]);
else if (action[0] == 'val') $(action[1]).val(action[2]);
+ // Class attribute
+ else if (action[0] == 'addClass') $(action[1]).addClass(action[2]);
+ else if (action[0] == 'removeClass') $(action[1]).removeClass(action[2]);
+ else if (action[0] == 'toggleClass') $(action[1]).toggleClass(action[2]);
+
// Data storage
else if (action[0] == 'data') $(action[1]).data(action[2], action[3]);
else if (action[0] == 'removeData') $(action[1]).removeData(action[2]);