| 1 | # ----------------------------------------------------------------------------- | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Quiq::JQuery::Accordion - Erzeuge HTML einer jQuery UI Accodion 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 Accordion 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 Accordion Reiterleiste. | ||||||||||
| 27 | |||||||||||
| 28 | =item class => $class (Default: undef) | ||||||||||
| 29 | |||||||||||
| 30 | CSS-Klasse der Accordion Reiterleiste. | ||||||||||
| 31 | |||||||||||
| 32 | =item tabs => \@arr (Default: []) | ||||||||||
| 33 | |||||||||||
| 34 | Definition der Accordion-Reiter. | ||||||||||
| 35 | |||||||||||
| 36 | =back | ||||||||||
| 37 | |||||||||||
| 38 | =head1 SEE ALSO | ||||||||||
| 39 | |||||||||||
| 40 | =over 2 | ||||||||||
| 41 | |||||||||||
| 42 | =item * | ||||||||||
| 43 | |||||||||||
| 44 | L<Accordion Widget API|http://api.jqueryui.com/accordion/> | ||||||||||
| 45 | |||||||||||
| 46 | =item * | ||||||||||
| 47 | |||||||||||
| 48 | L<Accordion Widget Beispiele|http://jqueryui.com/accordion/> | ||||||||||
| 49 | |||||||||||
| 50 | =back | ||||||||||
| 51 | |||||||||||
| 52 | =head1 EXAMPLE | ||||||||||
| 53 | |||||||||||
| 54 | Perl: | ||||||||||
| 55 | |||||||||||
| 56 | $html = Quiq::JQuery::Accordion->html($h, | ||||||||||
| 57 | id => 'accordion', | ||||||||||
| 58 | tabs => [{ | ||||||||||
| 59 | label => 'A', | ||||||||||
| 60 | link => 'a', | ||||||||||
| 61 | },{ | ||||||||||
| 62 | label => 'B', | ||||||||||
| 63 | content => $h->tag('p', | ||||||||||
| 64 | -text => 1, | ||||||||||
| 65 | 'Text des Reiters B', | ||||||||||
| 66 | ), | ||||||||||
| 67 | }], | ||||||||||
| 68 | ); | ||||||||||
| 69 | |||||||||||
| 70 | HTML: | ||||||||||
| 71 | |||||||||||
| 72 | <div id="accordion"> | ||||||||||
| 73 | <h3><a href="a">A</a></h3> | ||||||||||
| 74 | <div></div> | ||||||||||
| 75 | <h3>B</h3> | ||||||||||
| 76 | <div> | ||||||||||
| 77 | <p> | ||||||||||
| 78 | Text des Reiters B | ||||||||||
| 79 | </p> | ||||||||||
| 80 | </div> | ||||||||||
| 81 | </div> | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | # ----------------------------------------------------------------------------- | ||||||||||
| 86 | |||||||||||
| 87 | package Quiq::JQuery::Accordion; | ||||||||||
| 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 | |||||||||||
| 98 | # ----------------------------------------------------------------------------- | ||||||||||
| 99 | |||||||||||
| 100 | =head1 METHODS | ||||||||||
| 101 | |||||||||||
| 102 | =head2 Konstruktor | ||||||||||
| 103 | |||||||||||
| 104 | =head3 new() - Instantiiere Objekt | ||||||||||
| 105 | |||||||||||
| 106 | =head4 Synopsis | ||||||||||
| 107 | |||||||||||
| 108 | $obj = $class->new(@keyVal); | ||||||||||
| 109 | |||||||||||
| 110 | =head4 Description | ||||||||||
| 111 | |||||||||||
| 112 | Instantiiere ein Accordion-Objekt und liefere eine | ||||||||||
| 113 | Referenz auf dieses Objekt zurück. | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||
| 116 | |||||||||||
| 117 | # ----------------------------------------------------------------------------- | ||||||||||
| 118 | |||||||||||
| 119 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 120 | 2 | my $class = shift; | |||||||||
| 121 | # @_: @keyVal | ||||||||||
| 122 | |||||||||||
| 123 | 2 | my $self = $class->SUPER::new( | |||||||||
| 124 | class => undef, | ||||||||||
| 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=4 SCAR=13.9
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 ($class,$id,$tabA) = $self->get(qw/class id tabs/); | |||||||||
| 161 | |||||||||||
| 162 | 2 | for my $h (@$tabA) { | |||||||||
| 163 | 2 | Quiq::Hash->validateKeys($h,[qw/content label link/]); | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | return $h->tag('div', | ||||||||||
| 167 | -ignoreIfNull => 1, | ||||||||||
| 168 | id => $id, | ||||||||||
| 169 | class => $class, | ||||||||||
| 170 | '-', | ||||||||||
| 171 | 2 | do { | |||||||||
| 172 | 2 | my $html; | |||||||||
| 173 | 2 | for my $t (@$tabA) { | |||||||||
| 174 | 2 | my $url = $t->{'link'}; | |||||||||
| 175 | $html .= $h->cat( | ||||||||||
| 176 | $h->tag('h3', | ||||||||||
| 177 | $h->tag('a', | ||||||||||
| 178 | -ignoreTagIf => !$url, | ||||||||||
| 179 | href => $url, | ||||||||||
| 180 | $t->{'label'}, | ||||||||||
| 181 | ), | ||||||||||
| 182 | ), | ||||||||||
| 183 | $h->tag('div', | ||||||||||
| 184 | 2 | $t->{'content'}, | |||||||||
| 185 | ), | ||||||||||
| 186 | ); | ||||||||||
| 187 | } | ||||||||||
| 188 | 2 | $html; | |||||||||
| 189 | }, | ||||||||||
| 190 | ); | ||||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | # ----------------------------------------------------------------------------- | ||||||||||
| 194 | |||||||||||
| 195 | =head1 VERSION | ||||||||||
| 196 | |||||||||||
| 197 | 1.240 | ||||||||||
| 198 | |||||||||||
| 199 | =head1 AUTHOR | ||||||||||
| 200 | |||||||||||
| 201 | Frank Seitz, L<http://fseitz.de/> | ||||||||||
| 202 | |||||||||||
| 203 | =head1 COPYRIGHT | ||||||||||
| 204 | |||||||||||
| 205 | Copyright (C) 2026 Frank Seitz | ||||||||||
| 206 | |||||||||||
| 207 | =head1 LICENSE | ||||||||||
| 208 | |||||||||||
| 209 | This code is free software; you can redistribute it and/or modify | ||||||||||
| 210 | it under the same terms as Perl itself. | ||||||||||
| 211 | |||||||||||
| 212 | =cut | ||||||||||
| 213 | |||||||||||
| 214 | # ----------------------------------------------------------------------------- | ||||||||||
| 215 | |||||||||||
| 216 | 1 | 1; | |||||||||
| 217 | |||||||||||
| 218 | # eof | ||||||||||