help.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the Bugzilla Bug Tracking System.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 1998
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Gervase Markham <gerv@gerv.net>
  23. *
  24. * ***** END LICENSE BLOCK ***** */
  25. var g_helpTexts = new Object();
  26. var g_helpIframe;
  27. var g_helpDiv;
  28. /**
  29. * Generate help controls during page construction.
  30. *
  31. * @return Boolean; true if controls were created and false if not.
  32. */
  33. function generateHelp()
  34. {
  35. // Only enable help if controls can be hidden
  36. if (!document.body.style)
  37. return false;
  38. // Create help controls (a div to hold help text and an iframe
  39. // to mask any and all controls under the popup)
  40. document.write('<div id="helpDiv" style="display: none;"><\/div>');
  41. document.write('<iframe id="helpIframe" src="about:blank"');
  42. document.write(' frameborder="0" scrolling="no"><\/iframe>');
  43. return true;
  44. }
  45. /**
  46. * Enable help popups for all form elements after the page has finished loading.
  47. *
  48. * @return Boolean; true if help was enabled and false if not.
  49. */
  50. function enableHelp()
  51. {
  52. g_helpIframe = document.getElementById('helpIframe');
  53. g_helpDiv = document.getElementById('helpDiv');
  54. if (!g_helpIframe || !g_helpDiv) // Disabled if no controls found
  55. return false;
  56. // MS decided to add fieldsets to the elements array; and
  57. // Mozilla decided to copy this brokenness. Grr.
  58. for (var i = 0; i < document.forms.length; i++) {
  59. for (var j = 0; j < document.forms[i].elements.length; j++) {
  60. if (document.forms[i].elements[j].tagName != 'FIELDSET') {
  61. document.forms[i].elements[j].onmouseover = showHelp;
  62. }
  63. }
  64. }
  65. document.body.onclick = hideHelp;
  66. return true;
  67. }
  68. /**
  69. * Show the help popup for a form element.
  70. */
  71. function showHelp() {
  72. if (!g_helpIframe || !g_helpDiv || !g_helpTexts[this.name])
  73. return;
  74. // Get the position and size of the form element in the document
  75. var elemY = bz_findPosY(this);
  76. var elemX = bz_findPosX(this);
  77. var elemH = this.offsetHeight;
  78. // Update help text displayed in the div
  79. g_helpDiv.innerHTML = ''; // Helps IE 5 Mac
  80. g_helpDiv.innerHTML = g_helpTexts[this.name];
  81. // Position and display the help popup
  82. g_helpIframe.style.top = g_helpDiv.style.top = elemY + elemH + 5 + "px";
  83. g_helpIframe.style.left = g_helpDiv.style.left = elemX + "px";
  84. g_helpIframe.style.display = g_helpDiv.style.display = '';
  85. g_helpIframe.style.width = g_helpDiv.offsetWidth + "px";
  86. g_helpIframe.style.height = g_helpDiv.offsetHeight + "px";
  87. }
  88. /**
  89. * Hide the help popup.
  90. */
  91. function hideHelp() {
  92. if (!g_helpIframe || !g_helpDiv)
  93. return;
  94. g_helpIframe.style.display = g_helpDiv.style.display = 'none';
  95. }