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