Posted by Steven Tue 20th Mar 2007 23:38 - Syntax is JavaScript - 20 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Description:
Simple tooltip function...
Simple tooltip function...
-
/*
-
*
-
* Tooltip class - by Steven Bakhtiari 2007
-
*
-
* Requires Dom.class.js
-
*
-
* Simple tooltip that displays the title attribute of the tag.
-
*
-
*/
-
-
function Tooltip() {
-
-
var d = document;
-
-
dom.addListener(window, "load", init);
-
-
this.toolTip = false;
-
-
function init() {
-
links = d.getElementsByTagName("a");
-
for (var i = 0; i < links.length; i++) {
-
links[i].titleText = links[i].getAttribute("title");
-
links[i].removeAttribute("title");
-
links[i].onmouseover = showTip;
-
links[i].onmousemove = moveTip;
-
links[i].onmouseout = removeTip;
-
links[i].onclick = removeTip;
-
}
-
}
-
-
function showTip(ev) {
-
try {
-
if ((this.titleText) && (this.toolTip = createTip(this.titleText))) {
-
var coords = dom.getMousePos(ev);
-
this.toolTip.style.top = (coords['y']+20)+'px';
-
this.toolTip.style.left = (coords['x']+10)+'px';
-
d.getElementsByTagName('body')[0].appendChild(this.toolTip);
-
}
-
} catch(err) { } // catch any errors
-
}
-
-
function moveTip(ev) {
-
try {
-
var coords = dom.getMousePos(ev);
-
this.toolTip.style.top = (coords['y']+20)+'px';
-
this.toolTip.style.left = (coords['x']+10)+'px';
-
} catch(err) { } // catch any errors
-
}
-
-
function removeTip(ev) {
-
try {
-
dom.removeNode(this.toolTip);
-
} catch(err) { } // catch any errors
-
}
-
-
function createTip(text) {
-
tipElement = dom.newElement(d, "span");
-
tipElement.setAttribute("id", "tooltip");
-
tipElement.appendChild(dom.addText(d, text));
-
return tipElement;
-
}
-
-
}
-
PermaLink to this entry https://pastebin.co.uk/12105
Posted by Steven Tue 20th Mar 2007 23:38 - Syntax is JavaScript - 20 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0