| 1 | # ----------------------------------------------------------------------------- | ||||||||||||
| 2 | |||||||||||||
| 3 | =encoding utf8 | ||||||||||||
| 4 | |||||||||||||
| 5 | =head1 NAME | ||||||||||||
| 6 | |||||||||||||
| 7 | Quiq::JQuery::MenuBar - Erzeuge den Code einer jQuery Menüleiste | ||||||||||||
| 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 menüleiste. | ||||||||||||
| 16 | Dem Konstruktor werden die Menüpunktdefintionen mit dem Attribut | ||||||||||||
| 17 | C<items> übergeben. Die Methode L<html|"html() - Generiere HTML">() generiert den HTML-Code. | ||||||||||||
| 18 | |||||||||||||
| 19 | Homepage: | ||||||||||||
| 20 | |||||||||||||
| 21 | =over 2 | ||||||||||||
| 22 | |||||||||||||
| 23 | =item * | ||||||||||||
| 24 | |||||||||||||
| 25 | L<https://github.com/uSked/jquery-menubar> | ||||||||||||
| 26 | |||||||||||||
| 27 | =back | ||||||||||||
| 28 | |||||||||||||
| 29 | Quelldateien: | ||||||||||||
| 30 | |||||||||||||
| 31 | =over 2 | ||||||||||||
| 32 | |||||||||||||
| 33 | =item * | ||||||||||||
| 34 | |||||||||||||
| 35 | L<https://rawgit.com/ainterpreting/jquery-menubar/master/jquery.menubar.css> | ||||||||||||
| 36 | |||||||||||||
| 37 | =item * | ||||||||||||
| 38 | |||||||||||||
| 39 | L<https://rawgit.com/ainterpreting/jquery-menubar/master/jquery.menubar.js> | ||||||||||||
| 40 | |||||||||||||
| 41 | =back | ||||||||||||
| 42 | |||||||||||||
| 43 | B<Achtung:> Der Code läuft nur mit jQuery UI 1.11.4! | ||||||||||||
| 44 | |||||||||||||
| 45 | =over 2 | ||||||||||||
| 46 | |||||||||||||
| 47 | =item * | ||||||||||||
| 48 | |||||||||||||
| 49 | L<https://code.jquery.com/ui/1.11.4/themes/black-tie/jquery-ui.css> | ||||||||||||
| 50 | |||||||||||||
| 51 | =item * | ||||||||||||
| 52 | |||||||||||||
| 53 | L<https://code.jquery.com/ui/1.11.4/jquery-ui.min.js> | ||||||||||||
| 54 | |||||||||||||
| 55 | =back | ||||||||||||
| 56 | |||||||||||||
| 57 | =head1 ATTRIBUTES | ||||||||||||
| 58 | |||||||||||||
| 59 | =over 4 | ||||||||||||
| 60 | |||||||||||||
| 61 | =item id => $id (Default: 'menubar') | ||||||||||||
| 62 | |||||||||||||
| 63 | (String) CSS-Id der Menüleiste | ||||||||||||
| 64 | |||||||||||||
| 65 | =item items => \@arr (Default: []) | ||||||||||||
| 66 | |||||||||||||
| 67 | (Array of Hashes) Definition der Menüpunkte. | ||||||||||||
| 68 | |||||||||||||
| 69 | =item style => $style | ||||||||||||
| 70 | |||||||||||||
| 71 | CSS-Style. | ||||||||||||
| 72 | |||||||||||||
| 73 | =back | ||||||||||||
| 74 | |||||||||||||
| 75 | =cut | ||||||||||||
| 76 | |||||||||||||
| 77 | # ----------------------------------------------------------------------------- | ||||||||||||
| 78 | |||||||||||||
| 79 | package Quiq::JQuery::MenuBar; | ||||||||||||
| 80 | 1 | ▶ | use base qw/Quiq::Hash/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 81 | |||||||||||||
| 82 | 1 | ▶ | use v5.10; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 83 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 84 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 85 | |||||||||||||
| 86 | 1 | our $VERSION = '1.240'; | |||||||||||
| 87 | |||||||||||||
| 88 | # ----------------------------------------------------------------------------- | ||||||||||||
| 89 | |||||||||||||
| 90 | =head1 METHODS | ||||||||||||
| 91 | |||||||||||||
| 92 | =head2 Konstruktor | ||||||||||||
| 93 | |||||||||||||
| 94 | =head3 new() - Instantiiere Objekt | ||||||||||||
| 95 | |||||||||||||
| 96 | =head4 Synopsis | ||||||||||||
| 97 | |||||||||||||
| 98 | $obj = $class->new(@keyVal); | ||||||||||||
| 99 | |||||||||||||
| 100 | =head4 Description | ||||||||||||
| 101 | |||||||||||||
| 102 | Instantiiere ein Menüleisten-Objekt und liefere eine | ||||||||||||
| 103 | Referenz auf dieses Objekt zurück. | ||||||||||||
| 104 | |||||||||||||
| 105 | =cut | ||||||||||||
| 106 | |||||||||||||
| 107 | # ----------------------------------------------------------------------------- | ||||||||||||
| 108 | |||||||||||||
| 109 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 110 | 0 | my $class = shift; | |||||||||||
| 111 | # @_: @keyVal | ||||||||||||
| 112 | |||||||||||||
| 113 | 0 | my $self = $class->SUPER::new( | |||||||||||
| 114 | id => 'menubar', | ||||||||||||
| 115 | items => [], | ||||||||||||
| 116 | style => undef, | ||||||||||||
| 117 | ); | ||||||||||||
| 118 | 0 | $self->set(@_); | |||||||||||
| 119 | |||||||||||||
| 120 | 0 | return $self; | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | # ----------------------------------------------------------------------------- | ||||||||||||
| 124 | |||||||||||||
| 125 | =head2 Objektmethoden | ||||||||||||
| 126 | |||||||||||||
| 127 | =head3 html() - Generiere HTML | ||||||||||||
| 128 | |||||||||||||
| 129 | =head4 Synopsis | ||||||||||||
| 130 | |||||||||||||
| 131 | $html = $obj->html($h); | ||||||||||||
| 132 | $html = $class->html($h,@keyVal); | ||||||||||||
| 133 | |||||||||||||
| 134 | =head4 Description | ||||||||||||
| 135 | |||||||||||||
| 136 | Generiere den HTML-Code eines Menüleisten-Objekts und liefere | ||||||||||||
| 137 | diesen zurück. Als Klassenmethode gerufen, wird das Objekt intern | ||||||||||||
| 138 | mit den Attributen @keyVal instantiiert. | ||||||||||||
| 139 | |||||||||||||
| 140 | =cut | ||||||||||||
| 141 | |||||||||||||
| 142 | # ----------------------------------------------------------------------------- | ||||||||||||
| 143 | |||||||||||||
| 144 | 0 | ▶ | sub html { | ||||||||||
|
Subroutine
html: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 145 | 0 | my $this = shift; | |||||||||||
| 146 | 0 | my $h = shift; | |||||||||||
| 147 | |||||||||||||
| 148 | 0 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 149 | |||||||||||||
| 150 | 0 | my ($id,$itemA,$style) = $self->get(qw/id items style/); | |||||||||||
| 151 | |||||||||||||
| 152 | 0 | ▶ | if (!@$itemA) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 153 | 0 | return ''; | |||||||||||
| 154 | } | ||||||||||||
| 155 | |||||||||||||
| 156 | 0 | ▶ | $style = $style? "$style; display: none": 'display: none'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 157 | |||||||||||||
| 158 | # Menüstruktur rekursiv erzeugen | ||||||||||||
| 159 | |||||||||||||
| 160 | 0 | my $sub; | |||||||||||
| 161 | 0 | ▶ | $sub = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||
| 162 | 0 | my $itemA = shift; | |||||||||||
| 163 | 0 | ▶ | my $i = shift // 1; | ||||||||||
|
Condition0%0/2
shift() // 1
MC/DC0%0/1
shift() // 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 164 | |||||||||||||
| 165 | 0 | my $html = ''; | |||||||||||
| 166 | 0 | for my $itm (@$itemA) { | |||||||||||
| 167 | 0 | my $name = $itm->{'name'}; | |||||||||||
| 168 | 0 | my $url = $itm->{'url'}; | |||||||||||
| 169 | 0 | my $icon = $itm->{'icon'}; | |||||||||||
| 170 | 0 | ▶ | if ($icon) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 171 | 0 | $name = $h->tag('span', | |||||||||||
| 172 | -ignoreIfNull => 0, | ||||||||||||
| 173 | class => "ui-icon $icon" | ||||||||||||
| 174 | ).$name; | ||||||||||||
| 175 | } | ||||||||||||
| 176 | 0 | ▶ | my $tag = $url? $h->tag('a',href=>$url,$name): $name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 177 | 0 | ▶ | if (my $itemA = $itm->{'childs'}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 178 | 0 | $tag .= "\n".$sub->($itemA,$i+1); | |||||||||||
| 179 | } | ||||||||||||
| 180 | 0 | $html .= $h->tag('li',$tag); | |||||||||||
| 181 | } | ||||||||||||
| 182 | 0 | ▶ | $html = $h->tag('ul', | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 183 | $i == 1? (id=>$id): (), | ||||||||||||
| 184 | style => $style, | ||||||||||||
| 185 | $html | ||||||||||||
| 186 | ); | ||||||||||||
| 187 | |||||||||||||
| 188 | 0 | return $html; | |||||||||||
| 189 | 0 | }; | |||||||||||
| 190 | |||||||||||||
| 191 | 0 | my $html = $sub->($itemA); | |||||||||||
| 192 | 0 | $html .= $h->tag('script',q~ | |||||||||||
| 193 | var o = $('#menubar'); | ||||||||||||
| 194 | o.menubar(); | ||||||||||||
| 195 | o.show(); | ||||||||||||
| 196 | ~), | ||||||||||||
| 197 | |||||||||||||
| 198 | return $html; | ||||||||||||
| 199 | } | ||||||||||||
| 200 | |||||||||||||
| 201 | # ----------------------------------------------------------------------------- | ||||||||||||
| 202 | |||||||||||||
| 203 | =head1 VERSION | ||||||||||||
| 204 | |||||||||||||
| 205 | 1.240 | ||||||||||||
| 206 | |||||||||||||
| 207 | =head1 AUTHOR | ||||||||||||
| 208 | |||||||||||||
| 209 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||
| 210 | |||||||||||||
| 211 | =head1 COPYRIGHT | ||||||||||||
| 212 | |||||||||||||
| 213 | Copyright (C) 2026 Frank Seitz | ||||||||||||
| 214 | |||||||||||||
| 215 | =head1 LICENSE | ||||||||||||
| 216 | |||||||||||||
| 217 | This code is free software; you can redistribute it and/or modify | ||||||||||||
| 218 | it under the same terms as Perl itself. | ||||||||||||
| 219 | |||||||||||||
| 220 | =cut | ||||||||||||
| 221 | |||||||||||||
| 222 | # ----------------------------------------------------------------------------- | ||||||||||||
| 223 | |||||||||||||
| 224 | 1 | 1; | |||||||||||
| 225 | |||||||||||||
| 226 | # eof | ||||||||||||