Skip to content

Commit

Permalink
Merge pull request #19487 from Snuffleupagus/OverlayManager-closeIfAc…
Browse files Browse the repository at this point in the history
…tive

Add a new `closeIfActive` method in the `OverlayManager` class
  • Loading branch information
Snuffleupagus authored Feb 14, 2025
2 parents 6258a77 + 96f5dcb commit c69282a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
4 changes: 1 addition & 3 deletions web/alt_text_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ class AltTextManager {
}

#finish() {
if (this.#overlayManager.active === this.#dialog) {
this.#overlayManager.close(this.#dialog);
}
this.#overlayManager.closeIfActive(this.#dialog);
}

#close() {
Expand Down
8 changes: 2 additions & 6 deletions web/new_alt_text_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ class NewAltTextManager {
}

#finish() {
if (this.#overlayManager.active === this.#dialog) {
this.#overlayManager.close(this.#dialog);
}
this.#overlayManager.closeIfActive(this.#dialog);
}

#close() {
Expand Down Expand Up @@ -696,9 +694,7 @@ class ImageAltTextSettings {
}

#finish() {
if (this.#overlayManager.active === this.#dialog) {
this.#overlayManager.close(this.#dialog);
}
this.#overlayManager.closeIfActive(this.#dialog);
}
}

Expand Down
11 changes: 11 additions & 0 deletions web/overlay_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ class OverlayManager {
dialog.close();
this.#active = null;
}

/**
* @param {HTMLDialogElement} dialog - The overlay's DOM element.
* @returns {Promise} A promise that is resolved when the overlay has been
* closed.
*/
async closeIfActive(dialog) {
if (this.#active === dialog) {
await this.close(dialog);
}
}
}

export { OverlayManager };
4 changes: 1 addition & 3 deletions web/password_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ class PasswordPrompt {
}

async close() {
if (this.overlayManager.active === this.dialog) {
this.overlayManager.close(this.dialog);
}
this.overlayManager.closeIfActive(this.dialog);
}

#verify() {
Expand Down
8 changes: 2 additions & 6 deletions web/pdf_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ class PDFPrintService {
this.scratchCanvas = null;
activeService = null;
ensureOverlay().then(function () {
if (overlayManager.active === dialog) {
overlayManager.close(dialog);
}
overlayManager.closeIfActive(dialog);
});
}

Expand Down Expand Up @@ -260,9 +258,7 @@ window.print = function () {
if (!activeService) {
console.error("Expected print service to be initialized.");
ensureOverlay().then(function () {
if (overlayManager.active === dialog) {
overlayManager.close(dialog);
}
overlayManager.closeIfActive(dialog);
});
return; // eslint-disable-line no-unsafe-finally
}
Expand Down
8 changes: 2 additions & 6 deletions web/signature_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,7 @@ class SignatureManager {
}

#finish() {
if (this.#overlayManager.active === this.#dialog) {
this.#overlayManager.close(this.#dialog);
}
this.#overlayManager.closeIfActive(this.#dialog);
}

#close() {
Expand Down Expand Up @@ -993,9 +991,7 @@ class EditDescriptionDialog {
}

#finish() {
if (this.#overlayManager.active === this.#dialog) {
this.#overlayManager.close(this.#dialog);
}
this.#overlayManager.closeIfActive(this.#dialog);
}

#close() {
Expand Down

0 comments on commit c69282a

Please sign in to comment.