You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.6 KiB

3 years ago
  1. /* Your are permitted to reuse this code as long as the following copyright
  2. notice is not removed:
  3. This HTML tip handling is copyright 1998 by insideDHTML.com, LLC. More information about this
  4. code can be found at Inside Dynamic HTML: HTTP://www.insideDHTML.com
  5. */
  6. // Support for all collection
  7. var allSupport = document.all!=null;
  8. function setupEventObject(e) {
  9. // Map NS event object to IEs
  10. if (e==null) return; // IE returns
  11. window.event = e;
  12. window.event.fromElement = e.target;
  13. window.event.toElement = e.target;
  14. window.event.srcElement = e.target;
  15. window.event.x = e.x;
  16. window.event.y = e.y;
  17. // Route the event to the original element
  18. // Necessary to make sure _tip is set.
  19. window.event.srcElement.handleEvent(e);
  20. }
  21. function checkName(src) {
  22. // Look for tooltip in IE
  23. while ((src!=null) && (src._tip==null))
  24. src = src.parentElement;
  25. return src;
  26. }
  27. function getElement(elName) {
  28. // Get an element from its ID
  29. if (allSupport) return document.all[elName];
  30. else return document.layers[elName];
  31. }
  32. function writeContents(el, tip) {
  33. // Replace the contents of the tooltip
  34. if (allSupport)
  35. el.innerHTML = tip;
  36. else {
  37. // In NS, insert a table to work around
  38. // stylesheet rendering bug.
  39. // NS fails to apply style sheets when writing
  40. // contents into a positioned element.
  41. el.document.open();
  42. el.document.write("<TABLE WIDTH=200 BORDER=1 bordercolor=black><TR><TD WIDTH=100% BGCOLOR=yellow>");
  43. el.document.write(tip);
  44. el.document.write("</TD></TR></TABLE>");
  45. el.document.close();
  46. }
  47. }
  48. function getOffset(el, which) {
  49. // Function for IE to calculate position
  50. // of an element.
  51. var amount = el["offset"+which];
  52. if (which=="Top") amount+=el.offsetHeight;
  53. el = el.offsetParent;
  54. while (el!=null) {
  55. amount+=el["offset"+which];
  56. el = el.offsetParent;
  57. }
  58. return amount;
  59. }
  60. function setPosition(el) {
  61. // Set the position of an element
  62. src = window.event.srcElement
  63. if (allSupport) {
  64. el.style.pixelTop = getOffset(src, "Top");
  65. el.style.pixelLeft = getOffset(src, "Left");
  66. }
  67. else {
  68. el.top = src.y + 20; //window.event.y + 15
  69. el.left = src.x; //window.event.x
  70. }
  71. }
  72. function setVisibility(el, bDisplay) {
  73. // Hide or show to tip
  74. if (bDisplay) {
  75. if (allSupport) el.style.visibility = "visible";
  76. else el.visibility = "show";
  77. }
  78. else {
  79. if (allSupport) el.style.visibility = "hidden";
  80. else el.visibility = "hidden";
  81. }
  82. }
  83. function displayContents(tip) {
  84. // Display the tooltip.
  85. var el = getElement("tipBox");
  86. writeContents(el, tip);
  87. setPosition(el);
  88. setVisibility(el, true);
  89. }
  90. function doMouseOver(e) {
  91. // Mouse moves over an element
  92. setupEventObject(e);
  93. var el, tip;
  94. if ((el = checkName(window.event.srcElement))!=null) {
  95. if (!el._display) {
  96. displayContents(el._tip);
  97. el._display = true;
  98. }
  99. }
  100. }
  101. function doMouseOut(e) {
  102. // Mouse leaves an element
  103. setupEventObject(e);
  104. el = checkName(window.event.srcElement);
  105. var el, tip;
  106. if ((el = checkName(window.event.srcElement))!=null) {
  107. if (el._display) {
  108. if ((el.contains==null) || (!el.contains(window.event.toElement))) {
  109. setVisibility(getElement("tipBox"), false);
  110. el._display = false;
  111. }
  112. }
  113. }
  114. }
  115. function doLoad() {
  116. // Do Loading
  117. if ((window.document.captureEvents==null) && (!allSupport))
  118. return; // Not IE4 or NS4
  119. if (window.document.captureEvents!=null) // NS - capture events
  120. window.document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
  121. window.document.onmouseover = doMouseOver;
  122. window.document.onmouseout = doMouseOut;
  123. }
  124. window.onload = doLoad;