Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e5205a23

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID e5205a2352978ce3c665ecb5d7a017f308b7d139
  • Vorgänger c4e27e00
  • Nachfolger ffdfdc7e

L.tabbed - tab areale einfach erstellen.

Ausserdem einige neue html_tag Funktionen.

Conflicts:

SL/Template/Plugin/L.pm

Unterschiede anzeigen:

SL/Template/Plugin/L.pm
25 25
}
26 26

  
27 27
sub new {
28
  my $class   = shift;
29
  my $context = shift;
28
  my ($class, $context, @args) = @_;
30 29

  
31
  return bless { }, $class;
30
  return bless {
31
    CONTEXT => $context,
32
  }, $class;
33
}
34

  
35
sub _context {
36
  die 'not an accessor' if @_ > 1;
37
  return $_[0]->{CONTEXT};
32 38
}
33 39

  
34 40
sub name_to_id {
......
132 138
}
133 139

  
134 140
sub input_tag {
135
  my $self            = shift;
136
  my $name            = shift;
137
  my $value           = shift;
138
  my %attributes      = _hashify(@_);
141
  my ($self, $name, $value, @slurp) = @_;
142
  my %attributes                    = _hashify(@slurp);
139 143

  
140 144
  $attributes{id}   ||= $self->name_to_id($name);
141 145
  $attributes{type} ||= 'text';
......
147 151
  return shift->input_tag(@_, type => 'hidden');
148 152
}
149 153

  
154
sub div_tag {
155
  my ($self, $content, @slurp) = @_;
156
  return $self->html_tag('div', $content, @slurp);
157
}
158

  
159
sub ul_tag {
160
  my ($self, $content, @slurp) = @_;
161
  return $self->html_tag('ul', $content, @slurp);
162
}
163

  
164
sub li_tag {
165
  my ($self, $content, @slurp) = @_;
166
  return $self->html_tag('li', $content, @slurp);
167
}
168

  
169
sub link {
170
  my ($self, $href, $content, @slurp) = @_;
171
  my %params = _hashify(@slurp);
172

  
173
  $href ||= '#';
174

  
175
  return $self->html_tag('a', $content, %params, href => $href);
176
}
177

  
150 178
sub submit_tag {
151 179
  my $self             = shift;
152 180
  my $name             = shift;
......
233 261
    %params,
234 262
  ) .
235 263
  $self->javascript(
236
    "Calendar.setup({ inputField: '$name_e', ifFormat: '$datefmt', align: '$params{cal_align}', button: 'trigger$seq'  });"
264
    "Calendar.setup({ inputField: '$name_e', ifFormat: '$datefmt', align: '$params{cal_align}', button: 'trigger$seq' });"
237 265
  ) : '');
238 266

  
239 267
sub javascript_tag {
......
250 278
  return $code;
251 279
}
252 280

  
281
sub tabbed {
282
  my ($self, $tabs, @slurp) = @_;
283
  my %params   = _hashify(@slurp);
284
  my $id       = 'tab_' . _tag_id();
285

  
286
  $params{selected} *= 1;
287

  
288
  die 'L.tabbed needs an arrayred of tabs for first argument'
289
    unless ref $tabs eq 'ARRAY';
290

  
291
  my (@header, @blocks);
292
  for my $i (0..$#$tabs) {
293
    my $tab = $tabs->[$i];
294

  
295
    next if $tab eq '';
296

  
297
    my $selected = $params{selected} == $i;
298
    my $tab_id = _tag_id();
299
    push @header, $self->li_tag(
300
      $self->link('', $tab->{name}, rel => $tab_id),
301
        ($selected ? (class => 'selected') : ())
302
    );
303
    push @blocks, $self->div_tag($tab->{data},
304
      id => $tab_id, class => 'tabcontent');
305
  }
306

  
307
  return '' unless @header;
308
  return $self->ul_tag(
309
    join('', @header), id => $id, class => 'shadetabs'
310
  ) .
311
  $self->div_tag(
312
    join('', @blocks), class => 'tabcontentstyle'
313
  ) .
314
  $self->javascript(
315
    qq|var $id = new ddtabcontent("$id");$id.setpersist(true);| .
316
    qq|$id.setselectedClassTarget("link");$id.init();|
317
  );
318
}
319

  
320
sub tab {
321
  my ($self, $name, $src, @slurp) = @_;
322
  my %params = _hashify(@slurp);
323

  
324
  $params{method} ||= 'process';
325

  
326
  return () if defined $params{if} && !$params{if};
327

  
328
  my $data;
329
  if ($params{method} eq 'raw') {
330
    $data = $src;
331
  } elsif ($params{method} eq 'process') {
332
    $data = $self->_context->process($src, %{ $params{args} || {} });
333
  } else {
334
    die "unknown tag method '$params{method}'";
335
  }
336

  
337
  return () unless $data;
338

  
339
  return +{ name => $name, data => $data };
340
}
341

  
253 342
1;
254 343

  
255 344
__END__
......
381 470
postfixed with '.js' if it isn't already and prefixed with 'js/' if it
382 471
doesn't contain a slash.
383 472

  
473
=item C<date_tag $name, $value, cal_align =E<gt> $align_code, %attributes>
474

  
475
Creates a date input field, with an attached javascript that will open a
476
calendar on click. The javascript ist by default anchoered at the bottom right
477
sight. This can be overridden with C<cal_align>, see Calendar documentation for
478
the details, usually you'll want a two letter abbreviation of the alignment.
479
Right + Bottom becomes C<BL>.
480

  
481
=item C<tabbed \@tab, %attributes>
482

  
483
Will create a tabbed area. The tabs should be created with the helper function
484
C<tab>
485

  
384 486
=back
385 487

  
386 488
=head2 CONVERSION FUNCTIONS

Auch abrufbar als: Unified diff