Fixed bug with tooltip not viewable in a scrolled page.
[openemr.git] / library / js / ajtooltip.js
blob691f24a7f52f72083aaf9022a0c356e75c563d6b
1 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // See interface/reports/players_report.php for an example of
9 // implementing tooltips with this module.
11 // Helper functions.
12 function ttGetX(elem) {
13  var x = 0;
14  while(elem != null) {
15   x += elem.offsetLeft;
16   elem = elem.offsetParent;
17  }
18  return x;
20 function ttGetY(elem) {
21  var y = 0;
22  while(elem != null) {
23   y += elem.offsetTop;
24   elem = elem.offsetParent;
25  }
26  return y;
29 var ttTimerId = 0;
30 var ttElem = null;
31 var ttobject = null;
32 var ttUrl = '';
34 function ttClearTimer() {
35  if (ttTimerId) {
36   clearTimeout(ttTimerId);
37   ttTimerId = 0;
38   ttElem = null;
39   ttUrl = '';
40  }
43 // timer completion handler
44 function ttMake() {
45  ttobject = document.getElementById("tooltipdiv");
46  // ttobject.innerHTML = (ttTitle.length > 0) ? ttTitle : 'Loading...';
47  ttobject.innerHTML = '&nbsp;';
48  var x = ttGetX(ttElem);
49  var dw = window.innerWidth ? window.innerWidth - 20 : document.body.clientWidth;
50  if (dw && dw < (x + ttobject.offsetWidth)) {
51   x = dw - ttobject.offsetWidth;
52   if (x < 0) x = 0;
53  }
54  // var y = ttGetY(ttElem) - ttobject.offsetHeight - 10;
55  // if (y < 0) y = ttGetY(ttElem) + ttElem.offsetHeight + 10;
56  var dh = window.innerHeight ? window.innerHeight : document.body.clientHeight;
57  // var y = ttGetY(ttElem) + ttobject.offsetHeight + 10;
58  var y = ttGetY(ttElem) + ttElem.offsetHeight;
59  // if (y + 40 > dh) y = 0; // does not work for a scrolled page!
60  ttobject.style.left = x;
61  ttobject.style.top  = y;
62  ttobject.style.visibility='visible';
63  // if (!ttElem.ttTitle) {
64   myUrl = ttUrl;
65   $.getScript(ttUrl);
66  // }
67  ttTimerId = 0;
68  ttElem = null;
71 // onmouseover handler
72 function ttMouseOver(elem, url) {
73  ttClearTimer();
74  ttElem = elem;
75  ttUrl = url;
76  ttTimerId = setTimeout("ttMake()", 250);
77  return false;
80 // onmouseout handler.
81 function ttMouseOut() {
82  ttClearTimer();
83  var ttobject = document.getElementById("tooltipdiv");
84  ttobject.style.visibility='hidden';
85  ttobject.style.left = '-1000px';