michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var doOKFunction = 0; michael@0: var doCancelFunction = 0; michael@0: var doButton2Function = 0; michael@0: var doButton3Function = 0; michael@0: michael@0: // call this from dialog onload() to allow ok and cancel to call your code michael@0: // functions should return true if they want the dialog to close michael@0: function doSetOKCancel(okFunc, cancelFunc, button2Func, button3Func ) michael@0: { michael@0: //dump("top.window.navigator.platform: " + top.window.navigator.platform + "\n"); michael@0: michael@0: doOKFunction = okFunc; michael@0: doCancelFunction = cancelFunc; michael@0: doButton2Function = button2Func; michael@0: doButton3Function = button3Func; michael@0: } michael@0: michael@0: function doOKButton() michael@0: { michael@0: var close = true; michael@0: michael@0: if ( doOKFunction ) michael@0: close = doOKFunction(); michael@0: michael@0: if (close && top) michael@0: top.window.close(); michael@0: } michael@0: michael@0: function doCancelButton() michael@0: { michael@0: var close = true; michael@0: michael@0: if ( doCancelFunction ) michael@0: close = doCancelFunction(); michael@0: michael@0: if (close && top) michael@0: top.window.close(); michael@0: } michael@0: michael@0: function doButton2() michael@0: { michael@0: var close = true; michael@0: michael@0: if ( doButton2Function ) michael@0: close = doButton2Function(); michael@0: michael@0: if (close && top) michael@0: top.window.close(); michael@0: } michael@0: michael@0: function doButton3() michael@0: { michael@0: var close = true; michael@0: michael@0: if ( doButton3Function ) michael@0: close = doButton3Function(); michael@0: michael@0: if (close && top) michael@0: top.window.close(); michael@0: } michael@0: michael@0: function moveToAlertPosition() michael@0: { michael@0: // hack. we need this so the window has something like its final size michael@0: if (window.outerWidth == 1) { michael@0: dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n"); michael@0: sizeToContent(); michael@0: } michael@0: michael@0: var xOffset = (opener.outerWidth - window.outerWidth) / 2; michael@0: var yOffset = opener.outerHeight / 5; michael@0: michael@0: var newX = opener.screenX + xOffset; michael@0: var newY = opener.screenY + yOffset; michael@0: michael@0: // ensure the window is fully onscreen (if smaller than the screen) michael@0: if (newX < screen.availLeft) michael@0: newX = screen.availLeft + 20; michael@0: if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth)) michael@0: newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20; michael@0: michael@0: if (newY < screen.availTop) michael@0: newY = screen.availTop + 20; michael@0: if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight)) michael@0: newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60; michael@0: michael@0: window.moveTo( newX, newY ); michael@0: } michael@0: michael@0: function centerWindowOnScreen() michael@0: { michael@0: var xOffset = screen.availWidth/2 - window.outerWidth/2; michael@0: var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10; michael@0: michael@0: xOffset = ( xOffset > 0 ) ? xOffset : 0; michael@0: yOffset = ( yOffset > 0 ) ? yOffset : 0; michael@0: window.moveTo( xOffset, yOffset); michael@0: }