Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 20d730ac

Von Moritz Bunkus vor etwa 9 Jahren hinzugefügt

JavaScript-Plugin: auch als Filter einsetzen können

Unterschiede anzeigen:

SL/Template/Plugin/JavaScript.pm
1 1
package SL::Template::Plugin::JavaScript;
2 2

  
3
use base qw( Template::Plugin );
4
use Template::Plugin;
3
use base qw( Template::Plugin::Filter );
5 4

  
6 5
use strict;
7 6

  
7
my $cached_instance;
8

  
8 9
sub new {
9
  my ($class, $context, @args) = @_;
10
  my $class = shift;
11

  
12
  return $cached_instance ||= $class->SUPER::new(@_);
13
}
14

  
15
sub init {
16
  my $self = shift;
17

  
18
  $self->install_filter($self->{ _ARGS }->[0] || 'js');
10 19

  
11
  return bless {
12
    CONTEXT => $context,
13
  }, $class;
20
  return $self;
14 21
}
15 22

  
16 23
#
......
38 45
  return $text;
39 46
}
40 47

  
48
sub filter {
49
  my ($self, $text) = @_;
50
  return $self->escape($text);
51
}
52

  
41 53
sub replace_with {
42 54
  return _replace_helper('replaceWith', @_);
43 55
}
......
92 104
  <input type="submit" value="Delete"
93 105
         onclick="if (confirm('Do you really want to delete this: [% JavaScript.escape(obj.description) %]') return true; else return false;">
94 106

  
107
You can also use the filter syntax instead:
108

  
109
  <input type="submit" value="Delete"
110
         onclick="if (confirm('Do you really want to delete this: [% obj.description | js %]') return true; else return false;">
111

  
95 112
=item C<replace_with $selector, $template, %locals>
96 113

  
97 114
Returns code replacing the DOM elements matched by C<$selector> with

Auch abrufbar als: Unified diff