Skip to content

Commit 1bb725a

Browse files
committed
Use Element.moveBefore() to atomically move the page overlay container
Closes #6494
1 parent 1631a37 commit 1bb725a

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

ts/WoltLabSuite/Core/Helper/PageOverlay.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ const adoptiveParents: HTMLElement[] = [];
1212
export function adoptPageOverlayContainer(element: HTMLElement): void {
1313
adoptiveParents.push(element);
1414

15-
element.append(container);
15+
if ("moveBefore" in Element.prototype && document.body.contains(container)) {
16+
element.moveBefore(container, null);
17+
} else {
18+
element.append(container);
19+
}
1620
}
1721

1822
/**
@@ -42,7 +46,11 @@ export function releasePageOverlayContainer(element: HTMLElement): void {
4246
adoptiveParents.pop();
4347

4448
const previousParent = adoptiveParents[adoptiveParents.length - 1];
45-
previousParent.append(container);
49+
if ("moveBefore" in Element.prototype) {
50+
previousParent.moveBefore(container, null);
51+
} else {
52+
previousParent.append(container);
53+
}
4654

4755
return;
4856
}

ts/global.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,8 @@ declare global {
156156
"woltlab-core-reaction-summary": WoltlabCoreReactionSummaryElement;
157157
"woltlab-core-toggle-button": WoltlabCoreToggleButtonElement;
158158
}
159+
160+
interface Element {
161+
moveBefore(node: Element | CharacterData, child: Node | null): void;
162+
}
159163
}

wcfsetup/install/files/js/WoltLabSuite/Core/Helper/PageOverlay.js

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)