2 * JavaScript code to create "bubble tooltips"
4 * Copyright (C) 2006 Alessandro Fulciniti [http://web-graphics.com]
5 * Copyright (C) 2006 Art Cancro [http://www.citadel.org]
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.
13 function btt_enableTooltips(id)
16 if (!document.getElementById || !document.getElementsByTagName) {
20 h = document.createElement("span");
22 h.setAttribute("id", "btc");
23 h.style.position = "absolute";
24 document.getElementsByTagName("body")[0].appendChild(h);
26 links = document.getElementsByTagName("a");
29 links = document.getElementById(id).getElementsByTagName("a");
31 for (i = 0; i < links.length; i++) {
32 btt_Prepare(links[i]);
36 function btt_Prepare(el)
38 var tooltip, b, s, l, ih;
39 ih = el.getAttribute("btt_tooltext");
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(""));
49 tooltip.appendChild(s);
50 b = btt_CreateEl("b", "bottom");
51 tooltip.appendChild(b);
52 btt_setOpacity(tooltip);
54 el.onmouseover = btt_showTooltip;
55 el.onmouseout = btt_hideTooltip;
56 el.onmousemove = btt_Locate;
59 function btt_showTooltip(e)
61 document.getElementById("btc").appendChild(this.tooltip);
65 function btt_hideTooltip(e)
67 var d = document.getElementById("btc");
68 if (d.childNodes.length > 0) {
69 d.removeChild(d.firstChild);
73 function btt_setOpacity(el)
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";
81 function btt_CreateEl(t, c)
83 var x = document.createElement(t);
85 x.style.display = "block";
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);
99 function btt_Locate(e)
101 var posx = 0, posy = 0;
105 if (e.pageX || e.pageY) {
110 else if (e.clientX || e.clientY) {
111 if (document.documentElement.scrollTop) {
114 document.documentElement.scrollLeft;
116 e.clientY + document.documentElement.scrollTop;
120 posx = e.clientX + document.body.scrollLeft;
121 posy = e.clientY + document.body.scrollTop;
124 document.getElementById("btc").style.top = (posy + 10) + "px";
125 document.getElementById("btc").style.left = (posx - 260) + "px";