Repository navigation
Expand file tree
/
Copy pathHover.pm
More file actions
176 lines (117 loc) · 4.18 KB
/
Copy pathHover.pm
File metadata and controls
176 lines (117 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package WebComponent::Hover;
# Hover - component for a HoverMenu or HoverTooltip
use strict;
use warnings;
use base qw( WebComponent );
use Digest::MD5 qw( md5_hex );
1;
=pod
=head1 NAME
Hover - component for a HoverMenu or HoverTooltip
=head1 DESCRIPTION
WebComponent for a HoverMenu or HoverTooltip
=head1 METHODS
=over 4
=item * B<new> ()
Called when the object is initialized. Expands SUPER::new.
=cut
sub new {
my $self = shift->SUPER::new(@_);
$self->{tooltips} = [];
$self->{menus} = [];
$self->{redundancies} = {};
$self->{content_md5s} = {};
return $self;
}
=item * B<output> ()
Returns the html output of the Hover component.
=cut
sub output {
my ($self) = @_;
my $hover = "";
# calculate the redundancies string
my $redundancies_string = join( '~#', map { join( '~@', @{$self->redundancies->{$_}} ) } keys %{$self->redundancies});
$hover .= "<input type='hidden' id='hover_redundancies_".$self->id."' value='".$redundancies_string."'>";
foreach my $tooltip (@{$self->tooltips()}) {
$hover .= "<span style='display: none;' id='tooltip_" . $self->id . "_" . $tooltip->{id} . "'>" . $tooltip->{content} . "</span>\n";
if (defined($tooltip->{width})) {
$hover .= "<input type='hidden' id='tooltip_width_" . $self->id . "_" . $tooltip->{id} . "' value='" . $tooltip->{width} . "'>\n";
}
if (defined($tooltip->{timeout})) {
$hover .= "<input type='hidden' id='tooltip_timeout_" . $self->id . "_" . $tooltip->{id} . "' value='" . $tooltip->{timeout} . "'>\n";
}
}
foreach my $menu (@{$self->menus()}) {
$hover .= "<span style='display: none;' id='menu_titles_" . $self->id . "_" . $menu->{id} . "'>" . join('~#', @{$menu->{titles}}) . "</span>\n";
$hover .= "<span style='display: none;' id='menu_links_" . $self->id . "_" . $menu->{id} . "'>" . join('~#', @{$menu->{links}}) . "</span>\n";
if (defined($menu->{width})) {
$hover .= "<input type='hidden' id='menu_width_" . $self->id . "_" . $menu->{id} . "' value='" . $menu->{width} . "'>\n";
}
if (defined($menu->{timeout})) {
$hover .= "<input type='hidden' id='menu_timeout_" . $self->id . "_" . $menu->{id} . "' value='" . $menu->{timeout} . "'>\n";
}
}
return $hover;
}
=item * B<tooltips> ()
Getter for the tooltips attribute.
This is a container for all tooltips to be stored in this component.
=cut
sub tooltips {
my ($self) = @_;
return $self->{tooltips};
}
=item * B<redundancies> ()
Getter for the redundancies attribute.
This is a container for all redundant tooltip ids.
=cut
sub redundancies {
my ($self) = @_;
return $self->{redundancies};
}
=item * B<menus> ()
Getter for the menus attribute.
This is a container for all menus to be stored in this component.
=cut
sub menus {
my ($self) = @_;
return $self->{menus};
}
=item * B<add_tooltip> (I<id>, I<content>)
Adds a tooltip to the tooltips container.
B<id> must be the html-id of the object the tooltip is to be connected to.
B<content> holds the HTML to be show in the tolltip.
=cut
sub add_tooltip {
my ($self, $id, $content, $width, $timeout) = @_;
if (defined($id) && defined($content)) {
my $digest = md5_hex($content);
if (exists $self->redundancies->{$digest}) {
push(@{$self->redundancies->{$digest}}, $id);
} else {
$self->redundancies->{$digest} = [ $id ];
push(@{$self->{tooltips}}, { id => $id, content => $content, width => $width, timeout => $timeout });
}
}
return 1;
}
=item * B<add_menu> (I<id>, I<titles>, I<links>)
Adds a menu to the menus container.
B<id> must be the html-id of the object the menu is to be connected to.
B<titles> is an array reference, holding the titles of the menu entries
to be shown in the menu. B<links> is an array reference, holding the urls
the according menu entries should link to.
=cut
sub add_menu {
my ($self, $id, $titles, $links, $width, $timeout) = @_;
if (defined($id) && defined($titles) && defined($links)) {
push(@{$self->{menus}}, { id => $id, titles => $titles, links => $links, width => $width, timeout => $timeout });
}
return 1;
}
sub require_css {
return "$Conf::cgi_url/Html/Hover.css";
}
sub require_javascript {
return ["$Conf::cgi_url/Html/Hover.js"];
}