Source code of Windows XP (NT5)
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.

79 lines
2.5 KiB

  1. var g_popup = null;
  2. function GetPopup()
  3. {
  4. var popup = g_popup;
  5. if (null == popup)
  6. {
  7. popup = window.createPopup();
  8. if (popup)
  9. {
  10. popup.document.dir = window.document.dir;
  11. popup.document.body.style.cssText =
  12. "{ font:menu; border:'1px solid'; margin:0; padding:2px; color:infotext; background:infobackground; overflow:hidden; }";
  13. g_popup = popup;
  14. }
  15. }
  16. return popup;
  17. }
  18. function HidePopup()
  19. {
  20. if (g_popup)
  21. g_popup.hide();
  22. }
  23. function ShowPopup(szText, element, maxWidth)
  24. {
  25. var popup = GetPopup();
  26. if (popup && szText && szText.length > 0 && !popup.isOpen)
  27. {
  28. var lineHeight = 3 * element.offsetHeight / 2;
  29. var popupBody = popup.document.body;
  30. if (!maxWidth)
  31. maxWidth = 300;
  32. popupBody.innerText = szText;
  33. // Show first with small height to calculate actual dimensions
  34. popup.show(0, lineHeight, maxWidth, 6, element);
  35. var realWidth = popupBody.scrollWidth + popupBody.offsetWidth - popupBody.clientWidth;
  36. var realHeight = popupBody.scrollHeight + popupBody.offsetHeight - popupBody.clientHeight;
  37. if (realHeight < lineHeight && realWidth <= maxWidth)
  38. {
  39. // It's a short one-liner. Recalculate the width.
  40. popupBody.style.whiteSpace = 'nowrap'; // prevent line breaking
  41. popup.show(0, lineHeight, 6, realHeight, element);
  42. realWidth = popupBody.scrollWidth + popupBody.offsetWidth - popupBody.clientWidth;
  43. popupBody.style.whiteSpace = 'normal';
  44. }
  45. //
  46. // NTRAID#NTBUG9-391437-2001/05/14-jeffreys
  47. //
  48. // mshtml's popup positioning is screwed up on RTL, and they refuse to
  49. // fix it for compatibility reasons, so we have to compensate here.
  50. // (We now become one of the apps that require this behavior.)
  51. //
  52. var xPos = 0;
  53. if (window.document.dir == "rtl")
  54. {
  55. // This isn't quite correct, but rc.left is sometimes positive
  56. // and sometimes negative (go figure) which makes it hard to get
  57. // this exactly right. Close enough.
  58. var rc = element.getBoundingClientRect();
  59. xPos = element.document.body.offsetWidth - realWidth - (rc.left*2);
  60. }
  61. // Finally, show for real. Good thing this all happens on a single
  62. // thread so there is no flashing.
  63. popup.show(xPos, element.offsetHeight, realWidth, realHeight, element);
  64. }
  65. }