minor bug fix
[openemr.git] / library / tooltip.js
bloba5210d166baab6e803454cf7196ebc3d3dd08ce1
1 // Copyright (C) 2007 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/patient_file/history/encounters.php for an example of
9 // implementing tooltips with this module.
11 // Helper functions.
12 function getX(elem) {
13  var x = 0;
14  while(elem != null) {
15   x += elem.offsetLeft;
16   elem = elem.offsetParent;
17  }
18  return x;
20 function getY(elem) {
21  var y = 0;
22  while(elem != null) {
23   y += elem.offsetTop;
24   elem = elem.offsetParent;
25  }
26  return y;
29 // onmouseover handler.
30 function ttshow(elem, tttext) {
31  var ttobject = document.getElementById("tooltipdiv");
32  ttobject.innerHTML = tttext;
33  var x = getX(elem);
34  var dw = window.innerWidth ? window.innerWidth - 20 : document.body.clientWidth;
35  if (dw && dw < (x + ttobject.offsetWidth)) {
36   x = dw - ttobject.offsetWidth;
37   if (x < 0) x = 0;
38  }
39  var y = getY(elem) - ttobject.offsetHeight - 10;
40  if (y < 0) y = getY(elem) + elem.offsetHeight + 10;
41  ttobject.style.left = x;
42  ttobject.style.top  = y;
43  ttobject.style.visibility='visible';
44  return false;
47 // onmouseout handler.
48 function tthide() {
49  var ttobject = document.getElementById("tooltipdiv");
50  ttobject.style.visibility='hidden';
51  ttobject.style.left = '-1000px';