| 1 | # ----------------------------------------------------------------------------- | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Quiq::JQuery::Tabs - Erzeuge HTML einer jQuery UI Tabs Reiterleiste | ||||||||||
| 8 | |||||||||||
| 9 | =head1 BASE CLASS | ||||||||||
| 10 | |||||||||||
| 11 | L<Quiq::Hash> | ||||||||||
| 12 | |||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||
| 14 | |||||||||||
| 15 | Die Klasse erzeugt den HTML-Code einer jQuery UI Reiterleiste. | ||||||||||
| 16 | Dem Konstruktor wird die Reiterkonfiguration mit dem Attribut | ||||||||||
| 17 | C<tabs> übergeben. Die Methode L<html|"html() - Generiere HTML">() generiert den HTML-Code. | ||||||||||
| 18 | Siehe Abschnitt L<EXAMPLE|"EXAMPLE">. | ||||||||||
| 19 | |||||||||||
| 20 | =head1 ATTRIBUTES | ||||||||||
| 21 | |||||||||||
| 22 | =over 4 | ||||||||||
| 23 | |||||||||||
| 24 | =item id => $id (Default: undef) | ||||||||||
| 25 | |||||||||||
| 26 | DOM-Id der Reiterleiste. | ||||||||||
| 27 | |||||||||||
| 28 | =item tabs => \@arr (Default: []) | ||||||||||
| 29 | |||||||||||
| 30 | Definition der Reiter. | ||||||||||
| 31 | |||||||||||
| 32 | =back | ||||||||||
| 33 | |||||||||||
| 34 | =head1 SEE ALSO | ||||||||||
| 35 | |||||||||||
| 36 | =over 2 | ||||||||||
| 37 | |||||||||||
| 38 | =item * | ||||||||||
| 39 | |||||||||||
| 40 | L<Tabs Widget API|http://api.jqueryui.com/tabs/> | ||||||||||
| 41 | |||||||||||
| 42 | =item * | ||||||||||
| 43 | |||||||||||
| 44 | L<Tabs Widget Beispiele|http://jqueryui.com/tabs/> | ||||||||||
| 45 | |||||||||||
| 46 | =back | ||||||||||
| 47 | |||||||||||
| 48 | =head1 EXAMPLE | ||||||||||
| 49 | |||||||||||
| 50 | Perl: | ||||||||||
| 51 | |||||||||||
| 52 | $html = Quiq::JQuery::Tabs->html($h, | ||||||||||
| 53 | id => 'tabs', | ||||||||||
| 54 | tabs => [ | ||||||||||
| 55 | { | ||||||||||
| 56 | label => 'A', | ||||||||||
| 57 | link => '#a', | ||||||||||
| 58 | content => $h->tag('p', | ||||||||||
| 59 | -text => 1, | ||||||||||
| 60 | 'Text des Reiters A', | ||||||||||
| 61 | ), | ||||||||||
| 62 | },{ | ||||||||||
| 63 | label => 'B', | ||||||||||
| 64 | link => 'b', | ||||||||||
| 65 | }, | ||||||||||
| 66 | ], | ||||||||||
| 67 | ); | ||||||||||
| 68 | |||||||||||
| 69 | HTML: | ||||||||||
| 70 | |||||||||||
| 71 | <div id="tabs"> | ||||||||||
| 72 | <ul> | ||||||||||
| 73 | <li><a href="#a">A</a></li> | ||||||||||
| 74 | <li><a href="b">B</a></li> | ||||||||||
| 75 | </ul> | ||||||||||
| 76 | <div id="a"> | ||||||||||
| 77 | <p> | ||||||||||
| 78 | Text des Reiters A | ||||||||||
| 79 | </p> | ||||||||||
| 80 | </div> | ||||||||||
| 81 | </div> | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | # ----------------------------------------------------------------------------- | ||||||||||
| 86 | |||||||||||
| 87 | package Quiq::JQuery::Tabs; | ||||||||||
| 88 | 1 | ▶ | use base qw/Quiq::Hash/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 89 | |||||||||||
| 90 | 1 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 91 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 92 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 93 | |||||||||||
| 94 | 1 | our $VERSION = '1.240'; | |||||||||
| 95 | |||||||||||
| 96 | 1 | ▶ | use Quiq::Hash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 97 | 1 | ▶ | use Quiq::Html::List; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 98 | |||||||||||
| 99 | # ----------------------------------------------------------------------------- | ||||||||||
| 100 | |||||||||||
| 101 | =head1 METHODS | ||||||||||
| 102 | |||||||||||
| 103 | =head2 Konstruktor | ||||||||||
| 104 | |||||||||||
| 105 | =head3 new() - Instantiiere Objekt | ||||||||||
| 106 | |||||||||||
| 107 | =head4 Synopsis | ||||||||||
| 108 | |||||||||||
| 109 | $obj = $class->new(@keyVal); | ||||||||||
| 110 | |||||||||||
| 111 | =head4 Description | ||||||||||
| 112 | |||||||||||
| 113 | Instantiiere ein Reiterleisten-Objekt und liefere eine | ||||||||||
| 114 | Referenz auf dieses Objekt zurück. | ||||||||||
| 115 | |||||||||||
| 116 | =cut | ||||||||||
| 117 | |||||||||||
| 118 | # ----------------------------------------------------------------------------- | ||||||||||
| 119 | |||||||||||
| 120 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 121 | 2 | my $class = shift; | |||||||||
| 122 | # @_: @keyVal | ||||||||||
| 123 | |||||||||||
| 124 | 2 | my $self = $class->SUPER::new( | |||||||||
| 125 | id => undef, | ||||||||||
| 126 | tabs => [], | ||||||||||
| 127 | ); | ||||||||||
| 128 | 2 | $self->set(@_); | |||||||||
| 129 | |||||||||||
| 130 | 2 | return $self; | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | # ----------------------------------------------------------------------------- | ||||||||||
| 134 | |||||||||||
| 135 | =head2 Objektmethoden | ||||||||||
| 136 | |||||||||||
| 137 | =head3 html() - Generiere HTML | ||||||||||
| 138 | |||||||||||
| 139 | =head4 Synopsis | ||||||||||
| 140 | |||||||||||
| 141 | $html = $obj->html($h); | ||||||||||
| 142 | $html = $class->html($h,@keyVal); | ||||||||||
| 143 | |||||||||||
| 144 | =head4 Description | ||||||||||
| 145 | |||||||||||
| 146 | Generiere den HTML-Code eines Reiterleisten-Objekts und liefere | ||||||||||
| 147 | diesen zurück. Als Klassenmethode gerufen, wird das Objekt intern | ||||||||||
| 148 | mit den Attributen @keyVal instantiiert. | ||||||||||
| 149 | |||||||||||
| 150 | =cut | ||||||||||
| 151 | |||||||||||
| 152 | # ----------------------------------------------------------------------------- | ||||||||||
| 153 | |||||||||||
| 154 | 2 | ▶ | sub html { | ||||||||
|
Subroutine
html: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||
| 155 | 2 | my $this = shift; | |||||||||
| 156 | 2 | my $h = shift; | |||||||||
| 157 | |||||||||||
| 158 | 2 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | |||||||||||
| 160 | 2 | my ($id,$tabA) = $self->get(qw/id tabs/); | |||||||||
| 161 | |||||||||||
| 162 | 2 | ▶ | if (!@$tabA) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 163 | 1 | return ''; | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | 1 | for my $h (@$tabA) { | |||||||||
| 167 | 2 | Quiq::Hash->validateKeys($h,[qw/content label link/]); | |||||||||
| 168 | } | ||||||||||
| 169 | |||||||||||
| 170 | return $h->tag('div', | ||||||||||
| 171 | id => $id, | ||||||||||
| 172 | '-', | ||||||||||
| 173 | # <ul>-Abschnitt | ||||||||||
| 174 | Quiq::Html::List->html($h, | ||||||||||
| 175 | items => do{ | ||||||||||
| 176 | 1 | my @items; | |||||||||
| 177 | 1 | for my $t (@$tabA) { | |||||||||
| 178 | push @items,$h->tag('a', | ||||||||||
| 179 | href => $t->{'link'}, | ||||||||||
| 180 | 2 | $t->{'label'}, | |||||||||
| 181 | ); | ||||||||||
| 182 | } | ||||||||||
| 183 | 1 | \@items; | |||||||||
| 184 | }, | ||||||||||
| 185 | ), | ||||||||||
| 186 | # <div>-Abschnitt mit Unter-<divs> für jeden Reiter, | ||||||||||
| 187 | # dessen Content lokal definiert ist (Link referenziert Anker) | ||||||||||
| 188 | 1 | do { | |||||||||
| 189 | 1 | my $html = ''; | |||||||||
| 190 | 1 | for my $t (@$tabA) { | |||||||||
| 191 | 2 | ▶ | if (my ($anchor) = $t->{'link'} =~ /^#(.*)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 192 | $html .= $h->tag('div', | ||||||||||
| 193 | id => $anchor, | ||||||||||
| 194 | 1 | $t->{'content'} | |||||||||
| 195 | ); | ||||||||||
| 196 | } | ||||||||||
| 197 | } | ||||||||||
| 198 | 1 | $html; | |||||||||
| 199 | } | ||||||||||
| 200 | ); | ||||||||||
| 201 | } | ||||||||||
| 202 | |||||||||||
| 203 | # ----------------------------------------------------------------------------- | ||||||||||
| 204 | |||||||||||
| 205 | =head1 VERSION | ||||||||||
| 206 | |||||||||||
| 207 | 1.240 | ||||||||||
| 208 | |||||||||||
| 209 | =head1 AUTHOR | ||||||||||
| 210 | |||||||||||
| 211 | Frank Seitz, L<http://fseitz.de/> | ||||||||||
| 212 | |||||||||||
| 213 | =head1 COPYRIGHT | ||||||||||
| 214 | |||||||||||
| 215 | Copyright (C) 2026 Frank Seitz | ||||||||||
| 216 | |||||||||||
| 217 | =head1 LICENSE | ||||||||||
| 218 | |||||||||||
| 219 | This code is free software; you can redistribute it and/or modify | ||||||||||
| 220 | it under the same terms as Perl itself. | ||||||||||
| 221 | |||||||||||
| 222 | =cut | ||||||||||
| 223 | |||||||||||
| 224 | # ----------------------------------------------------------------------------- | ||||||||||
| 225 | |||||||||||
| 226 | 1 | 1; | |||||||||
| 227 | |||||||||||
| 228 | # eof | ||||||||||