* Removed AddCss() from bubble tooltips javascript. It isn't needed since we already...
[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 v3.
10  *
11  */
12
13 function btt_enableTooltips(id)
14 {
15         var links, i, h;
16         if (!document.getElementById || !document.getElementsByTagName) {
17                 return;
18         }
19         h = document.createElement("span");
20         h.id = "btc";
21         h.setAttribute("id", "btc");
22         h.style.position = "absolute";
23         document.getElementsByTagName("body")[0].appendChild(h);
24         if (id == null) {
25                 links = document.getElementsByTagName("a");
26         }
27         else {
28                 links = document.getElementById(id).getElementsByTagName("a");
29         }
30         for (i = 0; i < links.length; i++) {
31                 btt_Prepare(links[i]);
32         }
33 }
34
35 function btt_Prepare(el)
36 {
37         var tooltip, b, s, l, ih;
38         ih = el.getAttribute("btt_tooltext");
39         if (!ih) {
40                 return;
41         }
42         el.removeAttribute("btt_tooltext");
43         el.removeAttribute("title");
44         tooltip = btt_CreateEl("span", "tooltip");
45         s = btt_CreateEl("span", "top");
46         s.appendChild(document.createTextNode(""));
47         s.innerHTML = ih;
48         tooltip.appendChild(s);
49         b = btt_CreateEl("b", "bottom");
50         tooltip.appendChild(b);
51         btt_setOpacity(tooltip);
52         el.tooltip = tooltip;
53         el.onmouseover = btt_showTooltip;
54         el.onmouseout = btt_hideTooltip;
55         el.onmousemove = btt_Locate;
56 }
57
58 function btt_showTooltip(e)
59 {
60         document.getElementById("btc").appendChild(this.tooltip);
61         btt_Locate(e);
62 }
63
64 function btt_hideTooltip(e)
65 {
66         var d = document.getElementById("btc");
67         if (d.childNodes.length > 0) {
68                 d.removeChild(d.firstChild);
69         }
70 }
71
72 function btt_setOpacity(el)
73 {
74         el.style.filter = "alpha(opacity:95)";
75         el.style.KHTMLOpacity = "0.95";
76         el.style.MozOpacity = "0.95";
77         el.style.opacity = "0.95";
78 }
79
80 function btt_CreateEl(t, c)
81 {
82         var x = document.createElement(t);
83         x.className = c;
84         x.style.display = "block";
85         return (x);
86 }
87
88 function btt_Locate(e)
89 {
90         var posx = 0, posy = 0;
91         if (e == null) {
92                 e = window.event;
93         }
94         if (e.pageX || e.pageY) {
95                 posx = e.pageX;
96                 posy = e.pageY;
97         }
98         
99         else if (e.clientX || e.clientY) {
100                 if (document.documentElement.scrollTop) {
101                         posx =
102                             e.clientX +
103                             document.documentElement.scrollLeft;
104                         posy =
105                             e.clientY + document.documentElement.scrollTop;
106                 }
107                 
108                 else {
109                         posx = e.clientX + document.body.scrollLeft;
110                         posy = e.clientY + document.body.scrollTop;
111                 }
112         }
113         document.getElementById("btc").style.top = (posy + 10) + "px";
114         document.getElementById("btc").style.left = (posx - 260) + "px";
115 }