Toolbox/popUpBox/Browser/DOM.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 56 CC 3 SCAR 16.1
CC
3
Cov
0%
new
12.0
show
2.0
hide
2.0
CRAP 5.0
1 package JavaScript::Toolbox::popUpBox::Browser::DOM;
2
3 require v5.6;
4
5 use strict;
6 use warnings;
7
8 our $VERSION = '0.01';
9 use base qw(JavaScript::Toolbox::popUpBox::Browser);
10
11
12 sub new {
13 my ($proto, %args) = @_;
14
15 my $class = ref($proto) || $proto;
16 my $self = {};
17
18 if ($args{comply} eq 'IE') {
19 $self->{SCROLLOFFSET} = 'document.body.scrollTop';
20 } elsif ($args{comply} eq 'Opera') {
21 $self->{SCROLLOFFSET} = '0';
22 } else {
23 $self->{SCROLLOFFSET} = 'self.pageYOffset';
24 }
25
26 $self->{COMPLIANCE} = $args{comply};
27
28 bless ($self, $class);
29 return $self;
30 }
31
32 sub show {
33 my ($self, undef) = @_;
34
35 my $scrollOffset = $self->{SCROLLOFFSET};
36
37 my $code = qq{
38 // -- W3C Standards Compliance -- The JavaScript::Toolbox.
39 // -- DOM Level 2 JavaScript/ECMAScript language Bindings.
40 function showBox(event, content) {
41 var currentX, //mouse position on X axis
42 currentY, //mouse position on X axis
43 x, //layer target position on X axis
44 y, //layer target position on Y axis
45 docWidth, //width of current frame
46 docHeight, //height of current frame
47 layerWidth, //width of popup layer
48 layerHeight, //height of popup layer
49 popupElement; //points to the popup element
50
51 var name = 'popUpBox';
52
53 currentX = event.clientX,
54 currentY = event.clientY;
55 docHeight = document.height;
56 docWidth = document.width;
57
58 popupElement = document.getElementById(name);
59
60 layerWidth = popupElement.style.width;
61 layerHeight = popupElement.style.height;
62
63 // -- Calculate popup new position.
64 if ((currentX + layerWidth) > docWidth) {
65 x = (currentX - layerWidth);
66 } else {
67 x = currentX;
68 }
69
70 if ((currentY + layerHeight) >= docHeight) {
71 y = (currentY - layerHeight - 0);
72 } else {
73 y = currentY + 10;
74 }
75
76 // -- Adjust to Window Scrolling - Not part of the DOM.
77 y += $scrollOffset;
78
79 // -- Set content. Note: 'innerHTML' is not part of the
80 // -- DOM Spec. It is used here on the assumption that
81 // -- it will be part of it (innerText?) and because of
82 // -- its use since IE5 and Netscape 6 (this may change
83 // -- to be fully standards compliant).
84 //popupElement.innerHTML = self.pageYOffset;
85
86 // -- Set position and visibility.
87 popupElement.style.left = parseInt(x);
88 popupElement.style.top = parseInt(y);
89
90 popupElement.style.visibility = "visible";
91 }
92 };
93
94 return $code;
95 }
96
97 sub hide {
98 my $code = q{
99 function hideBox() {
100 var name = 'popUpBox';
101
102 document.getElementById(name).style.visibility = "hidden";
103 }
104 };
105
106 return $code;
107 }
108
109 sub javascript {
110 my ($self, %args) = @_;
111
112 my $show = $self->show();
113 my $hide = $self->hide();
114
115 my $code = qq{
116 <script language="JavaScript">
117 <!--
118 $show
119 $hide
120 //-->
121 </script>
122 };
123
124 return $code;
125 }
126
127 1;
128 __END__