Quiq/JQuery/ContextMenu.pm

filter: Statementstmt 100% 27 / 27 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 95.0% 38 / 40 CC 3 SCAR 5.2
CC
3
Cov
94%
js
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« Quiq/JQuery/Function.pm ↑ Summary Quiq/TempDir.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::JQuery::ContextMenu - Erzeuge Code für ein jQuery Kontext-Menü
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Die Klasse erzeugt Code für ein Kontext-Menü, welches durch das
16 jQuery-Plugin L<jQuery contextmenu|https://swisnl.github.io/jQuery-contextMenu/docs.html> realisiert wird.
17  
18 =head1 SEE ALSO
19  
20 =over 2
21  
22 =item *
23  
24 L<Allgmeine Doku|https://swisnl.github.io/jQuery-contextMenu/docs.html>
25  
26 =back
27  
28 =cut
29  
30 # -----------------------------------------------------------------------------
31  
32 package Quiq::JQuery::ContextMenu;
33 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 1 our $VERSION = '1.240';
40  
41 1 ▶use Quiq::Assert;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # -----------------------------------------------------------------------------
44  
45 =head1 METHODS
46  
47 =head2 Klassenmethoden
48  
49 =head3 new() - Konstruktor
50  
51 =head4 Synopsis
52  
53 $obj = $class->new(@keyVal);
54  
55 =head4 Attributes
56  
57 =over 4
58  
59 =item autoHide => $bool (Default: 0)
60  
61 Schließe das Menü, wenn der Mauszeiger das Triggerelement
62 oder das Menü verlässt.
63  
64 =item callback => $jsFunction
65  
66 Funktion, die bei Aufruf eines Menüpunkts gerufen wird. Beispiel:
67  
68 callback: function(key,opt) {
69 document.location = key;
70 },
71  
72 =item className => $name
73  
74 Name der CSS-Klasse des Menüs. Kann explizit angegeben werden, wenn das
75 Menü customized werden soll. Beispiel ($name ist 'contextMenu'):
76  
77 .contextMenu {
78 width: 85px !important;
79 min-width: 50px !important;
80 }
81  
82 =item items => \@items (Default: [])
83  
84 Array mit den Definitionen der Menüeinträge.
85  
86 Das JavaScript-Array C<data>, das vom Server geliefert wird, hat
87 den Aufbau
88  
89 [
90 $key => $j->object(
91 name => $name,
92 ...
93 ),
94 ...
95 ]
96  
97 =item selector => $selector
98  
99 Der jQuery-Selektor, der die Elemente identifiziert, auf die das
100 Kontext-Menü gelegt wird. Siehe Plugin-Doku: L<selector|https://swisnl.github.io/jQuery-contextMenu/docs.html#trigger>.
101  
102 =item trigger => $event
103  
104 Das Ereignis, durch das das Kontext-Menü angesprochen wird.
105 Siehe Plugin-Doku: L<tigger>.
106  
107 =back
108  
109 =head4 Description
110  
111 Instantiiere ein Objekt der Klasse und liefere eine Referenz auf dieses
112 Objekt zurück.
113  
114 =cut
115  
116 # -----------------------------------------------------------------------------
117  
118 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
119 1 my $class = shift;
120 # @_: @keyVal
121  
122 1 my $self = $class->SUPER::new(
123 autoHide => 0,
124 callback => undef,
125 className => undef,
126 items => [],
127 selector => undef,
128 trigger => undef,
129
130 );
131 1 $self->set(@_);
132  
133 1 return $self;
134 }
135  
136 # -----------------------------------------------------------------------------
137  
138 =head2 Objektmethoden
139  
140 =head3 js() - Generiere JavaScript-Code
141  
142 =head4 Synopsis
143  
144 $js = $obj->%METHOD($j);
145 $js = $class->%METHOD($j,@keyVal);
146  
147 =head4 Description
148  
149 Generiere den JavaScript-Code eines Kontext-Menüs und liefere
150 diesen zurück.
151  
152 =cut
153  
154 # -----------------------------------------------------------------------------
155  
156 1 ▶sub js {
Subroutine js: called CC=3 SCAR=11.2
Pod documented
157 1 my ($this,$j) = splice @_,0,2;
158 # @_: @keyVal
159  
160 1 ▶ my $self = ref $this? $this: $this->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 1 0 1
161  
162 # Objektattribute
163  
164 1 my ($autoHide,$callback,$className,$itemA,$selector,$trigger) =
165 $self->get(qw/autoHide callback className items selector trigger/);
166  
167 # Prüfe Attributwerte
168  
169 1 my $a = Quiq::Assert->new;
170 1 $a->isNotNull($callback,-name=>'callback');
171 1 $a->isNotNull($selector,-name=>'selector');
172  
173 # Generiere JavaScript-Code
174  
175 1 ▶ return '$.contextMenu('.$j->o(
Branch: 1 branch
BranchTrueFalseTotal
$autoHide ? : 0 1 1
176 className => $className,
177 selector => $selector,
178 trigger => $trigger,
179 autoHide => $autoHide? \'true': \'false',
180 callback => $j->code($callback),
181 items => $j->object(@$itemA),
182 ).');';
183 }
184  
185 # -----------------------------------------------------------------------------
186  
187 =head1 VERSION
188  
189 1.240
190  
191 =head1 AUTHOR
192  
193 Frank Seitz, L<http://fseitz.de/>
194  
195 =head1 COPYRIGHT
196  
197 Copyright (C) 2026 Frank Seitz
198  
199 =head1 LICENSE
200  
201 This code is free software; you can redistribute it and/or modify
202 it under the same terms as Perl itself.
203  
204 =cut
205  
206 # -----------------------------------------------------------------------------
207  
208 1 1;
209  
210 # eof
« Quiq/JQuery/Function.pm ↑ Summary Quiq/TempDir.pm »