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