summaryrefslogtreecommitdiff
path: root/httemplate/elements/link-replace_element_text.html
blob: 8e611954cc6ce5eacfc3d670882e0aaaf574cb81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<%doc>

Display a link with javascript to replace text within a element.

Usage:

<& /elements/link-replace_element_text.html, {
      target_id    => 'input_id',
      replace_text => 'hello',

      element_type => 'input', # Uses jquery val()  method to replace text
      element_type => 'div',   # Uses jquery text() method to replace text

      href  => ...
      style => ...
      class => ...
   }
&>

</%doc>
<a href="<% $param{href} %>"
   style="<% $param{style} %>"
% if ($param{class}) {
   class="<% $param{class} %>"
% }
   onClick="$('#<% $param{target_id} %>').<% $param{jmethod} %>('<% $param{replace_text} |h %>');">&#x25C1;</a>
<%init>

die "template call requires a parameter hashref" unless ref $_[0];

# Defaults that can be overridden in param hashref
my %param = (
    target_id    => 'SPECIFY_AN_INPUT_ELEMENT_ID',
    replace_text => 'REPLACEMENT_TEXT_FOR_INPUT_ELEMENT',
    element_type => 'input',

    link_text    => '%#x25C1;', # ◁
    href         => 'javascript:void(0)',
    style        => 'text-decoration:none;',
    class        => undef,

    %{ $_[0] },
);
$param{jmethod} = $param{element_type} eq 'input' ? 'val' : 'text';
</%init>