tooltip.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. var tooltipDiv = null;
  17. var tooltipPopup = null;
  18. var tooltipX = 0;
  19. var tooltipY = 0;
  20. var tooltipSrcObj = null;
  21. var tooltipCaptionColor = "#6699FF"; //"#808080";
  22. var tooltipBodyColor = "#FFFF99"; //"#C0C0C0";
  23. var tooltipBodyTextColor = "black";
  24. var tooltipMaxWidth = screen.width;
  25. function EnterContent(tooltipDivId, TTitle, TContent, nowrap, align)
  26. {
  27. var div = document.all[tooltipDivId];
  28. if (!div)
  29. return;
  30. var s = [];
  31. s.push('<table border="0" cellspacing="0" cellpadding="2px 0px 2px 0px" style="font:10pt serif; text-align:center; vertical-align:center"');
  32. if (nowrap)
  33. s.push(' width="100%"');
  34. s.push('>');
  35. if (TTitle)
  36. s.push('<tr><td ' + (nowrap ? 'nowrap="true"' : '') +
  37. ' bgcolor="'+tooltipCaptionColor+'">'+ TTitle+'</td></tr>');
  38. if (!align)
  39. align = 'left';
  40. s.push( '<tr><td align="' + align + '" ' + (nowrap ? 'nowrap="true"' : '') +
  41. ' bgcolor="'+tooltipBodyColor+'" style="color:' + tooltipBodyTextColor + '">'+
  42. TContent.replace(new RegExp('\n', 'g'), '<br/>')+
  43. '</td></tr></table>' );
  44. tooltipDiv = div;
  45. div.style.width = 0;//reset width
  46. div.innerHTML = s.join('');
  47. //if the tooltip is too wide then limit it to width defined by tooltipMaxWidth
  48. //
  49. if (tooltipDiv.offsetWidth > tooltipMaxWidth && nowrap)
  50. EnterContent(tooltipDivId, TTitle, TContent, false);
  51. }
  52. function tooltipContextMenu()
  53. {
  54. var srcObj = tooltipSrcObj;
  55. deActivate();
  56. return srcObj ? srcObj.oncontextmenu() : true;
  57. }
  58. function tooltipClick()
  59. {
  60. var srcObj = tooltipSrcObj;
  61. deActivate();
  62. return srcObj ? srcObj.onclick() : true;
  63. }
  64. function Activate(object, x, y)
  65. {
  66. if (tooltipDiv)
  67. {
  68. tooltipPopup=window.createPopup();
  69. var tooltipBody=tooltipPopup.document.body;
  70. //tooltipBody.style.backgroundColor = "yellow";
  71. tooltipBody.style.border = "outset black 1px";
  72. tooltipBody.innerHTML=tooltipDiv.innerHTML;
  73. if (object)
  74. {
  75. tooltipBody.oncontextmenu = tooltipContextMenu;
  76. tooltipBody.onclick = tooltipClick;
  77. }
  78. overhere(object, x, y);
  79. }
  80. }
  81. function overhere(object, x, y)
  82. {
  83. if (tooltipPopup && tooltipDiv)
  84. {
  85. if (object == null)
  86. {
  87. var e = window.event;
  88. if (e == null)
  89. return;
  90. x = e.screenX;
  91. y = e.screenY;
  92. object = tooltipSrcObj;
  93. }
  94. if (x != tooltipX || y != tooltipY || object != tooltipSrcObj)
  95. {
  96. tooltipX = x;
  97. tooltipY = y;
  98. tooltipSrcObj = object;
  99. tooltipPopup.show(tooltipX+5, tooltipY+5, tooltipDiv.offsetWidth+2, tooltipDiv.offsetHeight, object);
  100. }
  101. }
  102. }
  103. function deActivate()
  104. {
  105. if (tooltipPopup)
  106. {
  107. tooltipPopup.hide();
  108. tooltipPopup=null;
  109. tooltipX = tooltipY = 0;
  110. tooltipSrcObj = null;
  111. tooltipDiv = null;
  112. }
  113. }