mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Add a new closeIfActive
method in the OverlayManager
class
It's now pretty common that we only want to close a `dialog` *if* it's currently active, to avoid throwing errors, and this new method provides a shorter and more convenient way to achieve that.
This commit is contained in:
parent
6258a77bd7
commit
96f5dcbd91
6 changed files with 19 additions and 24 deletions
|
@ -245,9 +245,7 @@ class AltTextManager {
|
|||
}
|
||||
|
||||
#finish() {
|
||||
if (this.#overlayManager.active === this.#dialog) {
|
||||
this.#overlayManager.close(this.#dialog);
|
||||
}
|
||||
this.#overlayManager.closeIfActive(this.#dialog);
|
||||
}
|
||||
|
||||
#close() {
|
||||
|
|
|
@ -440,9 +440,7 @@ class NewAltTextManager {
|
|||
}
|
||||
|
||||
#finish() {
|
||||
if (this.#overlayManager.active === this.#dialog) {
|
||||
this.#overlayManager.close(this.#dialog);
|
||||
}
|
||||
this.#overlayManager.closeIfActive(this.#dialog);
|
||||
}
|
||||
|
||||
#close() {
|
||||
|
@ -696,9 +694,7 @@ class ImageAltTextSettings {
|
|||
}
|
||||
|
||||
#finish() {
|
||||
if (this.#overlayManager.active === this.#dialog) {
|
||||
this.#overlayManager.close(this.#dialog);
|
||||
}
|
||||
this.#overlayManager.closeIfActive(this.#dialog);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -148,9 +148,7 @@ class PDFPrintService {
|
|||
this.scratchCanvas = null;
|
||||
activeService = null;
|
||||
ensureOverlay().then(function () {
|
||||
if (overlayManager.active === dialog) {
|
||||
overlayManager.close(dialog);
|
||||
}
|
||||
overlayManager.closeIfActive(dialog);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -826,9 +826,7 @@ class SignatureManager {
|
|||
}
|
||||
|
||||
#finish() {
|
||||
if (this.#overlayManager.active === this.#dialog) {
|
||||
this.#overlayManager.close(this.#dialog);
|
||||
}
|
||||
this.#overlayManager.closeIfActive(this.#dialog);
|
||||
}
|
||||
|
||||
#close() {
|
||||
|
@ -993,9 +991,7 @@ class EditDescriptionDialog {
|
|||
}
|
||||
|
||||
#finish() {
|
||||
if (this.#overlayManager.active === this.#dialog) {
|
||||
this.#overlayManager.close(this.#dialog);
|
||||
}
|
||||
this.#overlayManager.closeIfActive(this.#dialog);
|
||||
}
|
||||
|
||||
#close() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue