webcit_before_automake is now the trunk
[citadel.git] / webcit / static / BubbleTooltips.js
1 /*
2  * JavaScript code to create "bubble tooltips"
3  * 
4  * Copyright (C) 2006 Alessandro Fulciniti [http://web-graphics.com]
5  * Copyright (C) 2006 Art Cancro [http://www.citadel.org]
6  *
7  * The original version of this module was released into the public
8  * domain.  This version is distributed as part of the Citadel system
9  * under the terms of the GNU General Public License v2.
10  *
11  */
12
13 function btt_enableTooltips(id)
14 {
15         var links, i, h;
16         if (!document.getElementById || !document.getElementsByTagName) {
17                 return;
18         }
19         btt_AddCss();
20         h = document.createElement("span");
21         h.id = "btc";
22         h.setAttribute("id", "btc");
23         h.style.position = "absolute";
24         document.getElementsByTagName("body")[0].appendChild(h);
25         if (id == null) {
26                 links = document.getElementsByTagName("a");
27         }
28         else {
29                 links = document.getElementById(id).getElementsByTagName("a");
30         }
31         for (i = 0; i < links.length; i++) {
32                 btt_Prepare(links[i]);
33         }
34 }
35
36 function btt_Prepare(el)
37 {
38         var tooltip, b, s, l, ih;
39         ih = el.getAttribute("btt_tooltext");
40         if (!ih) {
41                 return;
42         }
43         el.removeAttribute("btt_tooltext");
44         el.removeAttribute("title");
45         tooltip = btt_CreateEl("span", "tooltip");
46         s = btt_CreateEl("span", "top");
47         s.appendChild(document.createTextNode(""));
48         s.innerHTML = ih;
49         tooltip.appendChild(s);
50         b = btt_CreateEl("b", "bottom");
51         tooltip.appendChild(b);
52         btt_setOpacity(tooltip);
53         el.tooltip = tooltip;
54         el.onmouseover = btt_showTooltip;
55         el.onmouseout = btt_hideTooltip;
56         el.onmousemove = btt_Locate;
57 }
58
59 function btt_showTooltip(e)
60 {
61         document.getElementById("btc").appendChild(this.tooltip);
62         btt_Locate(e);
63 }
64
65 function btt_hideTooltip(e)
66 {
67         var d = document.getElementById("btc");
68         if (d.childNodes.length > 0) {
69                 d.removeChild(d.firstChild);
70         }
71 }
72
73 function btt_setOpacity(el)
74 {
75         el.style.filter = "alpha(opacity:95)";
76         el.style.KHTMLOpacity = "0.95";
77         el.style.MozOpacity = "0.95";
78         el.style.opacity = "0.95";
79 }
80
81 function btt_CreateEl(t, c)
82 {
83         var x = document.createElement(t);
84         x.className = c;
85         x.style.display = "block";
86         return (x);
87 }
88
89 function btt_AddCss()
90 {
91         var l = btt_CreateEl("link");
92         l.setAttribute("type", "text/css");
93         l.setAttribute("rel", "stylesheet");
94         l.setAttribute("href", "static/bt.css");
95         l.setAttribute("media", "screen");
96         document.getElementsByTagName("head")[0].appendChild(l);
97 }
98
99 function btt_Locate(e)
100 {
101         var posx = 0, posy = 0;
102         if (e == null) {
103                 e = window.event;
104         }
105         if (e.pageX || e.pageY) {
106                 posx = e.pageX;
107                 posy = e.pageY;
108         }
109         
110         else if (e.clientX || e.clientY) {
111                 if (document.documentElement.scrollTop) {
112                         posx =
113                             e.clientX +
114                             document.documentElement.scrollLeft;
115                         posy =
116                             e.clientY + document.documentElement.scrollTop;
117                 }
118                 
119                 else {
120                         posx = e.clientX + document.body.scrollLeft;
121                         posy = e.clientY + document.body.scrollTop;
122                 }
123         }
124         document.getElementById("btc").style.top = (posy + 10) + "px";
125         document.getElementById("btc").style.left = (posx - 260) + "px";
126 }