Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2cf9ebe3

Von Bernd Bleßmann vor 12 Monaten hinzugefügt

  • ID 2cf9ebe3c247b149d6ce698f937ba32905d5f4d7
  • Vorgänger b784a800
  • Nachfolger 2c7a0209

S:P:Tag: input_email_tag mit einem Icon und Link via "mailto:"

Unterschiede anzeigen:

SL/Presenter/Tag.pm
3 3
use strict;
4 4

  
5 5
use SL::HTML::Restrict;
6
use SL::Locale::String qw(t8);
6 7
use SL::Presenter::EscapedText qw(escape);
7 8
use Scalar::Util qw(blessed);
8 9

  
......
11 12
  html_tag input_tag hidden_tag javascript man_days_tag name_to_id select_tag
12 13
  checkbox_tag button_tag submit_tag ajax_submit_tag input_number_tag
13 14
  stringify_attributes textarea_tag link_tag date_tag
14
  div_tag radio_button_tag img_tag multi_level_select_tag input_tag_trim);
15
  div_tag radio_button_tag img_tag multi_level_select_tag input_tag_trim
16
  input_email_tag);
15 17
our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
16 18

  
17 19
use Carp;
......
509 511
  );
510 512
}
511 513

  
514
sub input_email_tag {
515
  my ($name, $value, %params) = @_;
516

  
517
  my $show_icon = $value || delete($params{show_icon_always});
518

  
519
  # _set_id_attribute removes the no_id param
520
  my $no_id_wanted = $params{no_id};
521
  _set_id_attribute(\%params, $name);
522
  $params{no_id} = $no_id_wanted;
523

  
524
  my $html = input_tag_trim($name, $value, %params);
525

  
526
  my $link_id   = $params{id} ? $params{id} . '_link' : undef;
527
  $html        .= link_tag(escape('mailto:' . $value),
528
                           img_tag(src => 'image/mail.png', alt => t8('Send email'), border => 0),
529
                           (id    => $link_id)x!!$link_id,
530
                           (style => 'display:none')x!$show_icon);
531

  
532
  return '<span>' . $html . '</span>';
533
}
512 534

  
513 535
sub javascript {
514 536
  my ($data) = @_;
......
674 696
$attributes{'data-validate'} and loads C<js/kivi.Validator.js>. This will trim
675 697
the whitespaces around the input.
676 698

  
699
=item C<input_email_tag $name, $value, %params>
700

  
701
This creates an C<input_tag_trim> and a C<link_tag> with an C<img_tag> for an
702
email icon. The link opens a 'mailto:' url with the value of the C<input_tag>.
703
The style of the C<link_tag> is set to 'display:none' if there is no value or
704
if the param C<show_icon_always> is truish.
705
All but the C<show_icon_always> params are forwared to the C<input_tag_trim>
706
as attributes.
707
This tag does not offer any javascript magic. The input value is only
708
evaluated when the tag is created.
709
The 'id' attrubute of the C<link_tag> is set to the 'id' of the C<input_tag>
710
with the string '_link' appended. This can be used to show/hide set the
711
C<link_tag> or set the link target dynamically.
712

  
677 713
=item C<submit_tag $name, $value, %attributes>
678 714

  
679 715
Creates a HTML 'input type=submit class=submit' tag named C<$name> with the
templates/webpages/presenter/test_page.html
19 19
                          defaults.to_date,
20 20
                          dialog_defaults => defaults.dialog) %]
21 21

  
22
<pre>presets: '1.2.2022', '3.4.2022', dialog: '2022', 'monthly', 'B', '6'</pre>
22
<pre>presets: '1.2.2022', '3.4.2022', dialog: '2022', 'monthly', 'B', '6'</pre>
23

  
24
<h2>Email Input</h2>
25
[% P.input_email_tag('email1', 'simple@test') %]<br>
26
[% P.input_email_tag('email2', 'id_given@test',     id => 'my_own_email_tag_id') %]<br>
27
[% P.input_email_tag('email3', 'no_id_wanted@test', no_id => 1) %]<br>
28
[% P.input_email_tag('email4', '', show_icon_always => 1) %] no value, but show_icon_always => 1<br>
29
[% P.input_email_tag('email5', '') %]no value, no icon
30
[% P.button_tag("if (\$('#email5').val() !== '') {\$('#email5_link').attr('href', 'mailto:'+\$('#email5').val()); \$('#email5_link').show();} else {\$('#email5_link').hide();}", 'update') %]<br>
31
[% P.input_email_tag('email6', '', onchange="if (\$('#email6').val() !== '') {\$('#email6_link').attr('href', 'mailto:'+\$('#email6').val()); \$('#email6_link').show();} else {\$('#email6_link').hide();}") %]no value, no icon, dynamically updated

Auch abrufbar als: Unified diff