X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FPresenter%2FEscapedText.pm;h=1c92f6fa9c918cb59ae53e5d09de9cfc3504abc1;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=ca3c8ca62f297c83bfc34a290aea3ab4bf5af80d;hpb=be5cae093b3218e8a1dcaa31911a43781ea3261f;p=kivitendo-erp.git diff --git a/SL/Presenter/EscapedText.pm b/SL/Presenter/EscapedText.pm index ca3c8ca62..1c92f6fa9 100644 --- a/SL/Presenter/EscapedText.pm +++ b/SL/Presenter/EscapedText.pm @@ -2,8 +2,9 @@ package SL::Presenter::EscapedText; use strict; use Exporter qw(import); +use Scalar::Util qw(looks_like_number); -our @EXPORT_OK = qw(escape is_escaped escape_js); +our @EXPORT_OK = qw(escape is_escaped escape_js escape_js_call); our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use JSON (); @@ -54,6 +55,20 @@ sub escape_js { __PACKAGE__->new(text => $text, is_escaped => 1); } +sub escape_js_call { + my ($func, @args) = @_; + + escape( + sprintf "%s(%s)", + escape_js($func), + join ", ", map { + looks_like_number($_) + ? $_ + : '"' . escape_js($_) . '"' + } @args + ); +} + # internal magic sub escaped_text { my ($self) = @_; @@ -141,6 +156,18 @@ Static constructor, can be exported. Equivalent to calling C<< new(text => $text Static constructor, can be exported. Like C but also escapes Javascript. +=item C + +Static constructor, can be exported. Used to construct a javascript call than +can be used for onclick handlers in other Presenter functions. + +For example: + + L.button_tag( + P.escape_js_call("kivi.Package.some_func", arg_one, arg_two, arg_three) + title + ) + =back =head1 METHODS