Implemented AJAX tooltips to show encounter form data from the encounters list.
[openemr.git] / library / js / ajtooltip.js
blob73159968f3a3d086b53cf1c8670a190e38773149
1 // Copyright (C) 2009, 2012 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 = '';
33 var ttWantContent = false;
35 function ttClearTimer() {
36  if (ttTimerId) {
37   clearTimeout(ttTimerId);
38   ttTimerId = 0;
39   ttElem = null;
40   ttUrl = '';
41  }
42  ttWantContent = false;
45 // timer completion handler
46 function ttMake() {
47  ttWantContent = true;
48  top.restoreSession();
49  $.get(ttUrl, function(data) {
50   if (!ttWantContent) return;
51   ttobject = document.getElementById("tooltipdiv");
52   ttobject.innerHTML = data;
53   var x = ttGetX(ttElem);
54   var dw = window.innerWidth ? window.innerWidth - 20 : document.body.clientWidth;
55   if (dw && dw < (x + ttobject.offsetWidth)) {
56    x = dw - ttobject.offsetWidth;
57    if (x < 0) x = 0;
58   }
59   var dh = window.innerHeight ? window.innerHeight : document.body.clientHeight;
60   var y = ttGetY(ttElem) + ttElem.offsetHeight;
61   ttobject.style.left = x;
62   ttobject.style.top  = y;
63   ttobject.style.visibility='visible';
64   ttWantContent = false;
65   ttElem = null;
66  });
67  ttTimerId = 0;
70 // onmouseover handler
71 function ttMouseOver(elem, url) {
72  ttClearTimer();
73  ttElem = elem;
74  ttUrl = url;
75  ttTimerId = setTimeout("ttMake()", 250);
76  return false;
79 // onmouseout handler.
80 function ttMouseOut() {
81  ttClearTimer();
82  var ttobject = document.getElementById("tooltipdiv");
83  ttobject.style.visibility='hidden';
84  ttobject.style.left = '-1000px';