helptip_wev8.js
2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* This script was created by Erik Arvidsson (erik(at)eae.net)
* for WebFX (http://webfx.eae.net)
* Copyright 2001
*
* For usage see license at http://webfx.eae.net/license.html
*
* Version: 1.0
* Created: 2001-09-27
* Updated: 2001-11-25 Added a resize to the tooltip if the document width is too small
*
* Dependencies: helptip_wev8.css (To set up the CSS of the help-tooltip class)
*
* Usage:
*
* <script type="text/javascript" src="helptip_wev8.js"></script>
* <link type="text/css" rel="StyleSheet" href="helptip_wev8.css" />
*
* <a class="helpLink" href="?" onclick="showHelp(event, 'String to show'); return false">Help</a>
*
*/
function showHelpTip(e, s) {
// find anchor element
var el = e.target ? e.target : e.srcElement;
while (el.tagName != "A")
el = el.parentNode;
// is there already a tooltip? If so, remove it
if (el._helpTip) {
document.body.removeChild(el._helpTip);
el._helpTip = null;
el.onblur = null;
return;
}
// create element and insert last into the body
var d = document.createElement("DIV");
d.className = "help-tooltip";
document.body.appendChild(d);
d.innerHTML = s;
// Allow clicks on A elements inside tooltip
d.onmousedown = function (e) {
if (!e) e = event;
var t = e.target ? e.target : e.srcElement;
while (t.tagName != "A" && t != d)
t = t.parentNode;
if (t == d) return;
el._onblur = el.onblur;
el.onblur = null;
};
d.onmouseup = function () {
el.onblur = el._onblur;
el.focus();
};
// position tooltip
var dw = document.width ? document.width : document.documentElement.offsetWidth - 25;
if (d.offsetWidth >= dw)
d.style.width = dw - 10 + "px";
else
d.style.width = "";
var scroll = getScroll();
if (e.clientX > dw - d.offsetWidth)
d.style.left = dw - d.offsetWidth + scroll.x + "px";
else
d.style.left = e.clientX - 2 + scroll.x + "px";
d.style.top = e.clientY + 18 + scroll.y + "px";
// add a listener to the blur event. When blurred remove tooltip and restore anchor
el.onblur = function () {
document.body.removeChild(d);
el.onblur = null;
el._helpTip = null;
};
// store a reference to the tooltip div
el._helpTip = d;
}
// returns the scroll left and top for the browser viewport.
function getScroll() {
if (document.all && document.body.scrollTop != undefined) { // IE model
var ieBox = document.compatMode != "CSS1Compat";
var cont = ieBox ? document.body : document.documentElement;
return {x : cont.scrollLeft, y : cont.scrollTop};
}
else {
return {x : window.pageXOffset, y : window.pageYOffset};
}
}