Skip to content

Commit ac322c1

Browse files
fix window manager target element
1 parent d7e185d commit ac322c1

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/wiki/util/openWindow.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import unwrapWidget from '../../util/unwrapWidget';
22
import removeElement from '../../util/removeElement';
33

4+
export let windowManager: OO.ui.WindowManager;
5+
46
/**
57
* Opens a temporary window. Use this for dialogs that are immediately destroyed
68
* after running. Do NOT use this for re-openable dialogs, such as the main ANTE
@@ -11,15 +13,22 @@ import removeElement from '../../util/removeElement';
1113
*/
1214
export default async function openWindow( window: OO.ui.Window ): Promise<void> {
1315
return new Promise( ( res ) => {
14-
let wm = new OO.ui.WindowManager();
15-
document.getElementsByTagName( 'body' )[ 0 ].appendChild( unwrapWidget( wm ) );
16-
wm.addWindows( [ window ] );
17-
wm.openWindow( window );
18-
wm.on( 'closing', ( win, closed ) => {
16+
if ( !windowManager ) {
17+
windowManager = new OO.ui.WindowManager();
18+
const parent = document.getElementById( 'mw-teleport-target' ) ??
19+
document.getElementsByTagName( 'body' )[ 0 ];
20+
21+
parent.appendChild(
22+
unwrapWidget( windowManager )
23+
);
24+
}
25+
windowManager.addWindows( [ window ] );
26+
windowManager.openWindow( window );
27+
windowManager.on( 'closing', ( win, closed ) => {
1928
closed.then( () => {
20-
if ( wm ) {
21-
const _wm = wm;
22-
wm = null;
29+
if ( windowManager ) {
30+
const _wm = windowManager;
31+
windowManager = null;
2332
removeElement( unwrapWidget( _wm ) );
2433
_wm.destroy();
2534
res();

0 commit comments

Comments
 (0)