dialogOverlay.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. var doOKFunction = 0;
  5. var doCancelFunction = 0;
  6. var doButton2Function = 0;
  7. var doButton3Function = 0;
  8. // call this from dialog onload() to allow ok and cancel to call your code
  9. // functions should return true if they want the dialog to close
  10. function doSetOKCancel(okFunc, cancelFunc, button2Func, button3Func )
  11. {
  12. //dump("top.window.navigator.platform: " + top.window.navigator.platform + "\n");
  13. doOKFunction = okFunc;
  14. doCancelFunction = cancelFunc;
  15. doButton2Function = button2Func;
  16. doButton3Function = button3Func;
  17. }
  18. function doOKButton()
  19. {
  20. var close = true;
  21. if ( doOKFunction )
  22. close = doOKFunction();
  23. if (close && top)
  24. top.window.close();
  25. }
  26. function doCancelButton()
  27. {
  28. var close = true;
  29. if ( doCancelFunction )
  30. close = doCancelFunction();
  31. if (close && top)
  32. top.window.close();
  33. }
  34. function doButton2()
  35. {
  36. var close = true;
  37. if ( doButton2Function )
  38. close = doButton2Function();
  39. if (close && top)
  40. top.window.close();
  41. }
  42. function doButton3()
  43. {
  44. var close = true;
  45. if ( doButton3Function )
  46. close = doButton3Function();
  47. if (close && top)
  48. top.window.close();
  49. }
  50. function moveToAlertPosition()
  51. {
  52. // hack. we need this so the window has something like its final size
  53. if (window.outerWidth == 1) {
  54. dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n");
  55. sizeToContent();
  56. }
  57. if (opener) {
  58. var xOffset = (opener.outerWidth - window.outerWidth) / 2;
  59. var yOffset = opener.outerHeight / 5;
  60. var newX = opener.screenX + xOffset;
  61. var newY = opener.screenY + yOffset;
  62. } else {
  63. newX = (screen.availWidth - window.outerWidth) / 2;
  64. newY = (screen.availHeight - window.outerHeight) / 2;
  65. }
  66. // ensure the window is fully onscreen (if smaller than the screen)
  67. if (newX < screen.availLeft)
  68. newX = screen.availLeft + 20;
  69. if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth))
  70. newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20;
  71. if (newY < screen.availTop)
  72. newY = screen.availTop + 20;
  73. if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight))
  74. newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60;
  75. window.moveTo( newX, newY );
  76. }
  77. function centerWindowOnScreen()
  78. {
  79. var xOffset = screen.availWidth/2 - window.outerWidth/2;
  80. var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10;
  81. xOffset = ( xOffset > 0 ) ? xOffset : 0;
  82. yOffset = ( yOffset > 0 ) ? yOffset : 0;
  83. window.moveTo( xOffset, yOffset);
  84. }