136
|
1 |
/* EventCalendar. Copyright (C) 2005, Alex Tingle. $Revision: 65 $ |
|
2 |
* This file is licensed under the GNU GPL. See LICENSE file for details. |
|
3 |
*/ |
|
4 |
|
|
5 |
/** class ec3_Popup */ |
|
6 |
function ec3_Popup() |
|
7 |
{ |
|
8 |
|
|
9 |
WindowOnload( function() |
|
10 |
{ |
|
11 |
var calendars=ec3.get_calendars(); |
|
12 |
if(!calendars) |
|
13 |
return; |
|
14 |
// Pre-load images. |
|
15 |
ec3.imgShadow0=new Image(8,32); |
|
16 |
ec3.imgShadow1=new Image(500,16); |
|
17 |
ec3.imgShadow2=new Image(8,32); |
|
18 |
ec3.imgShadow0.src=ec3.myfiles+'/shadow0.png'; |
|
19 |
ec3.imgShadow1.src=ec3.myfiles+'/shadow1.png'; |
|
20 |
ec3.imgShadow2.src=ec3.myfiles+'/shadow2.png'; |
|
21 |
|
|
22 |
// Generate the popup (but keep it hidden). |
|
23 |
var table,tbody,tr,td; |
|
24 |
ec3_Popup.popup=document.createElement('table'); |
|
25 |
ec3_Popup.popup.style.display='none'; |
|
26 |
ec3_Popup.popup.id='ec3_popup'; |
|
27 |
ec3_Popup.popup.className='ec3_popup'; |
|
28 |
tbody=ec3_Popup.popup.appendChild( document.createElement('tbody') ); |
|
29 |
tr=tbody.appendChild( document.createElement('tr') ); |
|
30 |
td=tr.appendChild( document.createElement('td') ); |
|
31 |
td.id='ec3_shadow0'; |
|
32 |
td.rowSpan=2; |
|
33 |
td.appendChild( document.createElement('div') ); |
|
34 |
td=tr.appendChild( document.createElement('td') ); |
|
35 |
ec3_Popup.contents=td.appendChild( document.createElement('table') ); |
|
36 |
ec3_Popup.contents.style.width=500; |
|
37 |
td=tr.appendChild( document.createElement('td') ); |
|
38 |
td.id='ec3_shadow2'; |
|
39 |
td.rowSpan=2; |
|
40 |
td.appendChild( document.createElement('div') ); |
|
41 |
tr=tbody.appendChild( document.createElement('tr') ); |
|
42 |
td=tr.appendChild( document.createElement('td') ); |
|
43 |
td.id='ec3_shadow1'; |
|
44 |
|
|
45 |
document.body.appendChild(ec3_Popup.popup); |
|
46 |
|
|
47 |
// Add event handlers to the calendars. |
|
48 |
for(var i=0; i<calendars.length; i++) |
|
49 |
add_tbody( ec3.get_child_by_tag_name(calendars[i],'tbody') ); |
|
50 |
} ); |
|
51 |
|
|
52 |
function add_tbody(tbody) |
|
53 |
{ |
|
54 |
if(!tbody) |
|
55 |
return; |
|
56 |
var anchor_list=tbody.getElementsByTagName('a'); |
|
57 |
if(!anchor_list) |
|
58 |
return; |
|
59 |
for(var i=0; i<anchor_list.length; i++) |
|
60 |
{ |
|
61 |
var a=anchor_list[i]; |
|
62 |
var td=a.parentNode; |
|
63 |
// 'title' might have become 'nicetitle' if that plugin is being run. |
|
64 |
var titleattr=a.getAttribute('nicetitle'); |
|
65 |
if(!titleattr) |
|
66 |
titleattr=a.getAttribute('title'); |
|
67 |
if(titleattr && td.nodeName=='TD' && td.className!='pad') |
|
68 |
{ |
|
69 |
td.setAttribute('ec3_title',titleattr); |
|
70 |
a.removeAttribute('nicetitle'); |
|
71 |
a.removeAttribute('title'); |
|
72 |
addEvent(td,'mouseover',show); |
|
73 |
addEvent(td,'mouseout',hide); |
|
74 |
addEvent(td,'focus',show); |
|
75 |
addEvent(td,'blur',hide); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
ec3_Popup.add_tbody=add_tbody; |
|
80 |
|
|
81 |
function show(e) |
|
82 |
{ |
|
83 |
var n; |
|
84 |
if(e.currentTarget) |
|
85 |
n=e.currentTarget; // Mozilla/Safari/w3c |
|
86 |
else if(window.event) |
|
87 |
n=window.event.srcElement; // IE |
|
88 |
else |
|
89 |
return; |
|
90 |
|
|
91 |
// Find the TD element and the calendar node. |
|
92 |
// (IE will sometimes randomly give us a child instead). |
|
93 |
var td,cal; |
|
94 |
while(1) |
|
95 |
{ |
|
96 |
if(!n || n==document.body) |
|
97 |
{ |
|
98 |
return; |
|
99 |
} |
|
100 |
else if(n.tagName=='TABLE') |
|
101 |
{ |
|
102 |
cal=n; |
|
103 |
break; |
|
104 |
} |
|
105 |
else if(n.tagName=='TD') |
|
106 |
{ |
|
107 |
td=n; |
|
108 |
} |
|
109 |
n=n.parentNode; |
|
110 |
} |
|
111 |
|
|
112 |
var ec3_title=td.getAttribute('ec3_title'); |
|
113 |
if(typeof ec3_title == 'undefined') |
|
114 |
return; |
|
115 |
if(ec3_Popup.just_hidden) |
|
116 |
ec3_Popup.popup.style.display = "block"; |
|
117 |
else |
|
118 |
ec3_Popup.show_timer=setTimeout( |
|
119 |
function(){ec3_Popup.popup.style.display = "block";}, |
|
120 |
600 |
|
121 |
); |
|
122 |
|
|
123 |
ec3_Popup.contents.style.width=''+(cal.offsetWidth-2)+'px'; |
|
124 |
ec3_Popup.popup.style.top=''+(findPosY(cal)+cal.offsetHeight)+'px'; |
|
125 |
ec3_Popup.popup.style.left=''+(findPosX(cal)-8)+'px'; |
|
126 |
|
|
127 |
var tbody=ec3.get_child_by_tag_name(ec3_Popup.contents,'tbody'); |
|
128 |
if(tbody) |
|
129 |
ec3_Popup.contents.removeChild(tbody); |
|
130 |
tbody=ec3_Popup.contents.appendChild(document.createElement('tbody')); |
|
131 |
|
|
132 |
var titles=ec3_title.split(', '); |
|
133 |
for(var i=0; i<titles.length; i++) |
|
134 |
{ |
|
135 |
tr=tbody.appendChild(document.createElement('tr')); |
|
136 |
td=tr.appendChild(document.createElement('td')); |
|
137 |
td.appendChild(document.createTextNode(titles[i])); |
|
138 |
if(titles[i].indexOf('@')!=-1) |
|
139 |
td.className='eventday'; |
|
140 |
} |
|
141 |
|
|
142 |
// Let's put this event to a halt before it starts messing things up |
|
143 |
window.event? window.event.cancelBubble=true: e.stopPropagation(); |
|
144 |
} |
|
145 |
|
|
146 |
function hide() |
|
147 |
{ |
|
148 |
if(ec3_Popup.show_timer) |
|
149 |
clearTimeout(ec3_Popup.show_timer); |
|
150 |
if(ec3_Popup.popup.style.display!='none') |
|
151 |
{ |
|
152 |
ec3_Popup.just_hidden=1; |
|
153 |
ec3_Popup.hide_timer=setTimeout(function(){ec3_Popup.just_hidden=0;},900); |
|
154 |
} |
|
155 |
ec3_Popup.popup.style.display='none'; |
|
156 |
|
|
157 |
} |
|
158 |
|
|
159 |
//===================================================================== |
|
160 |
// Event Listener |
|
161 |
// by Scott Andrew - http://scottandrew.com |
|
162 |
// edited by Mark Wubben, <useCapture> is now set to false |
|
163 |
//===================================================================== |
|
164 |
function addEvent(obj, evType, fn){ |
|
165 |
if(obj.addEventListener){ |
|
166 |
obj.addEventListener(evType, fn, false); |
|
167 |
return true; |
|
168 |
} else if (obj.attachEvent){ |
|
169 |
var r = obj.attachEvent('on'+evType, fn); |
|
170 |
return r; |
|
171 |
} else { |
|
172 |
return false; |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
//===================================================================== |
|
177 |
// From http://www.quirksmode.org/ |
|
178 |
//===================================================================== |
|
179 |
function findPosX(obj) |
|
180 |
{ |
|
181 |
var curleft = 0; |
|
182 |
if (obj.offsetParent) |
|
183 |
{ |
|
184 |
while(1) |
|
185 |
{ |
|
186 |
curleft += obj.offsetLeft; |
|
187 |
if(!obj.offsetParent) break; |
|
188 |
obj = obj.offsetParent; |
|
189 |
} |
|
190 |
} |
|
191 |
else if (obj.x) |
|
192 |
curleft += obj.x; |
|
193 |
return curleft; |
|
194 |
} |
|
195 |
|
|
196 |
function findPosY(obj) |
|
197 |
{ |
|
198 |
var curtop = 0; |
|
199 |
if (obj.offsetParent) |
|
200 |
{ |
|
201 |
while(1) |
|
202 |
{ |
|
203 |
curtop += obj.offsetTop; |
|
204 |
if(!obj.offsetParent) break; |
|
205 |
obj = obj.offsetParent; |
|
206 |
} |
|
207 |
} |
|
208 |
else if (obj.y) |
|
209 |
curtop += obj.y; |
|
210 |
return curtop; |
|
211 |
} |
|
212 |
|
|
213 |
} // end namespace ec3_Popup |
|
214 |
|
|
215 |
// Export public functions from ec3_Popup namespace. |
|
216 |
ec3_Popup(); |