mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38: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() {
|
#finish() {
|
||||||
if (this.#overlayManager.active === this.#dialog) {
|
this.#overlayManager.closeIfActive(this.#dialog);
|
||||||
this.#overlayManager.close(this.#dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#close() {
|
#close() {
|
||||||
|
|
|
@ -440,9 +440,7 @@ class NewAltTextManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#finish() {
|
#finish() {
|
||||||
if (this.#overlayManager.active === this.#dialog) {
|
this.#overlayManager.closeIfActive(this.#dialog);
|
||||||
this.#overlayManager.close(this.#dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#close() {
|
#close() {
|
||||||
|
@ -696,9 +694,7 @@ class ImageAltTextSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
#finish() {
|
#finish() {
|
||||||
if (this.#overlayManager.active === this.#dialog) {
|
this.#overlayManager.closeIfActive(this.#dialog);
|
||||||
this.#overlayManager.close(this.#dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,17 @@ class OverlayManager {
|
||||||
dialog.close();
|
dialog.close();
|
||||||
this.#active = null;
|
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 };
|
export { OverlayManager };
|
||||||
|
|
|
@ -89,9 +89,7 @@ class PasswordPrompt {
|
||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
if (this.overlayManager.active === this.dialog) {
|
this.overlayManager.closeIfActive(this.dialog);
|
||||||
this.overlayManager.close(this.dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#verify() {
|
#verify() {
|
||||||
|
|
|
@ -148,9 +148,7 @@ class PDFPrintService {
|
||||||
this.scratchCanvas = null;
|
this.scratchCanvas = null;
|
||||||
activeService = null;
|
activeService = null;
|
||||||
ensureOverlay().then(function () {
|
ensureOverlay().then(function () {
|
||||||
if (overlayManager.active === dialog) {
|
overlayManager.closeIfActive(dialog);
|
||||||
overlayManager.close(dialog);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,9 +258,7 @@ window.print = function () {
|
||||||
if (!activeService) {
|
if (!activeService) {
|
||||||
console.error("Expected print service to be initialized.");
|
console.error("Expected print service to be initialized.");
|
||||||
ensureOverlay().then(function () {
|
ensureOverlay().then(function () {
|
||||||
if (overlayManager.active === dialog) {
|
overlayManager.closeIfActive(dialog);
|
||||||
overlayManager.close(dialog);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return; // eslint-disable-line no-unsafe-finally
|
return; // eslint-disable-line no-unsafe-finally
|
||||||
}
|
}
|
||||||
|
|
|
@ -826,9 +826,7 @@ class SignatureManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#finish() {
|
#finish() {
|
||||||
if (this.#overlayManager.active === this.#dialog) {
|
this.#overlayManager.closeIfActive(this.#dialog);
|
||||||
this.#overlayManager.close(this.#dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#close() {
|
#close() {
|
||||||
|
@ -993,9 +991,7 @@ class EditDescriptionDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
#finish() {
|
#finish() {
|
||||||
if (this.#overlayManager.active === this.#dialog) {
|
this.#overlayManager.closeIfActive(this.#dialog);
|
||||||
this.#overlayManager.close(this.#dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#close() {
|
#close() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue