forked from LibreHealthIO/lh-ehr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtooltip.js
52 lines (48 loc) · 1.39 KB
/
tooltip.js
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
// Copyright (C) 2007 Rod Roark <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// See interface/patient_file/history/encounters.php for an example of
// implementing tooltips with this module.
// Helper functions.
function getX(elem) {
var x = 0;
while(elem != null) {
x += elem.offsetLeft;
elem = elem.offsetParent;
}
return x;
}
function getY(elem) {
var y = 0;
while(elem != null) {
y += elem.offsetTop;
elem = elem.offsetParent;
}
return y;
}
// onmouseover handler.
function ttshow(elem, tttext) {
var ttobject = document.getElementById("tooltipdiv");
ttobject.innerHTML = tttext;
var x = getX(elem);
var dw = window.innerWidth ? window.innerWidth - 20 : document.body.clientWidth;
if (dw && dw < (x + ttobject.offsetWidth)) {
x = dw - ttobject.offsetWidth;
if (x < 0) x = 0;
}
var y = getY(elem) - ttobject.offsetHeight - 10;
if (y < 0) y = getY(elem) + elem.offsetHeight + 10;
ttobject.style.left = x;
ttobject.style.top = y;
ttobject.style.visibility='visible';
return false;
}
// onmouseout handler.
function tthide() {
var ttobject = document.getElementById("tooltipdiv");
ttobject.style.visibility='hidden';
ttobject.style.left = '-1000px';
}