Revision d5b3ea19
Von Sven Schöling vor fast 4 Jahren hinzugefügt
SL/Presenter/EscapedText.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
use Exporter qw(import); |
5 |
use Scalar::Util qw(looks_like_number); |
|
5 | 6 |
|
6 |
our @EXPORT_OK = qw(escape is_escaped escape_js); |
|
7 |
our @EXPORT_OK = qw(escape is_escaped escape_js escape_js_call);
|
|
7 | 8 |
our %EXPORT_TAGS = (ALL => \@EXPORT_OK); |
8 | 9 |
|
9 | 10 |
use JSON (); |
... | ... | |
54 | 55 |
__PACKAGE__->new(text => $text, is_escaped => 1); |
55 | 56 |
} |
56 | 57 |
|
58 |
sub escape_js_call { |
|
59 |
my ($func, @args) = @_; |
|
60 |
|
|
61 |
escape( |
|
62 |
sprintf "%s(%s)", |
|
63 |
escape_js($func), |
|
64 |
join ", ", map { |
|
65 |
looks_like_number($_) |
|
66 |
? $_ |
|
67 |
: '"' . escape_js($_) . '"' |
|
68 |
} @args |
|
69 |
); |
|
70 |
} |
|
71 |
|
|
57 | 72 |
# internal magic |
58 | 73 |
sub escaped_text { |
59 | 74 |
my ($self) = @_; |
... | ... | |
141 | 156 |
|
142 | 157 |
Static constructor, can be exported. Like C<escape> but also escapes Javascript. |
143 | 158 |
|
159 |
=item C<escape_js_call $func_name, @args> |
|
160 |
|
|
161 |
Static constructor, can be exported. Used to construct a javascript call than |
|
162 |
can be used for onclick handlers in other Presenter functions. |
|
163 |
|
|
164 |
For example: |
|
165 |
|
|
166 |
L.button_tag( |
|
167 |
P.escape_js_call("kivi.Package.some_func", arg_one, arg_two, arg_three) |
|
168 |
title |
|
169 |
) |
|
170 |
|
|
144 | 171 |
=back |
145 | 172 |
|
146 | 173 |
=head1 METHODS |
Auch abrufbar als: Unified diff
Presenter::EscapedText: escape_js_calls
Helferfunktion um das manuelle Zusammenstückeln von onclick Callbacks zu
erleichtern.