forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajtooltip.js
86 lines (78 loc) · 2 KB
/
ajtooltip.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
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
// Copyright (C) 2009, 2012 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/reports/players_report.php for an example of
// implementing tooltips with this module.
// Helper functions.
function ttGetX(elem) {
var x = 0;
while(elem != null) {
x += elem.offsetLeft;
elem = elem.offsetParent;
}
return x;
}
function ttGetY(elem) {
var y = 0;
while(elem != null) {
y += elem.offsetTop;
elem = elem.offsetParent;
}
return y;
}
var ttTimerId = 0;
var ttElem = null;
var ttobject = null;
var ttUrl = '';
var ttWantContent = false;
function ttClearTimer() {
if (ttTimerId) {
clearTimeout(ttTimerId);
ttTimerId = 0;
ttElem = null;
ttUrl = '';
}
ttWantContent = false;
}
// timer completion handler
function ttMake() {
ttWantContent = true;
top.restoreSession();
$.get(ttUrl, function(data) {
if (!ttWantContent) return;
ttobject = document.getElementById("tooltipdiv");
ttobject.innerHTML = data;
var x = ttGetX(ttElem);
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 dh = window.innerHeight ? window.innerHeight : document.body.clientHeight;
var y = ttGetY(ttElem) + ttElem.offsetHeight;
ttobject.style.left = x;
ttobject.style.top = y;
ttobject.style.visibility='visible';
ttWantContent = false;
ttElem = null;
});
ttTimerId = 0;
}
// onmouseover handler
function ttMouseOver(elem, url) {
ttClearTimer();
ttElem = elem;
ttUrl = url;
ttTimerId = setTimeout("ttMake()", 250);
return false;
}
// onmouseout handler.
function ttMouseOut() {
ttClearTimer();
var ttobject = document.getElementById("tooltipdiv");
ttobject.style.visibility='hidden';
ttobject.style.left = '-1000px';
}