home *** CD-ROM | disk | FTP | other *** search
/ Chip 2009 November / Chip_2009.11_CD.iso / I386 / nusrmgr.cp_ / nusrmgr.cpl / HTML / POPUP.JS < prev    next >
Encoding:
Text File  |  2008-04-14  |  1.4 KB  |  52 lines

  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. popup.show(0, lineHeight, maxWidth, 6, element);
  34. var realWidth = popupBody.scrollWidth + popupBody.offsetWidth - popupBody.clientWidth;
  35. var realHeight = popupBody.scrollHeight + popupBody.offsetHeight - popupBody.clientHeight;
  36. if (realHeight < lineHeight && realWidth <= maxWidth)
  37. {
  38. popupBody.style.whiteSpace = 'nowrap'; 
  39. popup.show(0, lineHeight, 6, realHeight, element);
  40. realWidth = popupBody.scrollWidth + popupBody.offsetWidth - popupBody.clientWidth;
  41. popupBody.style.whiteSpace = 'normal';
  42. }
  43. var xPos = 0;
  44. if (window.document.dir == "rtl")
  45. {
  46. var rc = element.getBoundingClientRect();
  47. xPos = element.document.body.offsetWidth - realWidth - (rc.left*2);
  48. }
  49. popup.show(xPos, element.offsetHeight, realWidth, realHeight, element);
  50. }
  51. }
  52.