-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AUT-1539] - Child Window Pop up option (#46)
* [AUT-1539] - Child Window Pop up option * add window handler logic * cleanup * Rename consts/functions * Tweak import --------- Co-authored-by: Hamish Meikle <[email protected]>
- Loading branch information
1 parent
ef06f74
commit 135bd78
Showing
6 changed files
with
142 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {WindowHandler} from "./window-handler"; | ||
export {PopupHandler} from "./popup-handler"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
type WindowShowInput = { | ||
url: string; | ||
width?: number; | ||
height?: number; | ||
}; | ||
|
||
const DEFAULT_WIDTH = 400; | ||
const DEFAULT_HEIGHT = 500; | ||
|
||
export class WindowHandler { | ||
private windowRef: Window | null = null; | ||
|
||
show({url, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT}: WindowShowInput) { | ||
const windowRef = openWindow({url, width, height, win: window}); | ||
|
||
if (!windowRef) { | ||
throw new Error("Window is not initialized"); | ||
} | ||
|
||
this.windowRef = windowRef; | ||
|
||
return windowRef; | ||
} | ||
|
||
close() { | ||
if (!this.windowRef) { | ||
throw new Error("Window is not initialized"); | ||
} | ||
|
||
this.windowRef.close(); | ||
} | ||
} | ||
|
||
type OpenWindowInput = { | ||
url: string; | ||
width: number; | ||
height: number; | ||
win: Window; | ||
}; | ||
|
||
function openWindow({url, width, height, win}: OpenWindowInput): Window | null { | ||
if (!win.top) { | ||
return null; | ||
} | ||
|
||
const y = win.top.outerHeight / 2 + win.top.screenY - height / 2; | ||
const x = win.top.outerWidth / 2 + win.top.screenX - width / 2; | ||
|
||
return window.open( | ||
url, | ||
"", | ||
`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${width}, height=${height}, top=${y}, left=${x}` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters