mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
confirm if leaving a modified form without saving
This commit is contained in:
parent
965d20db2a
commit
83365a3756
4 changed files with 94 additions and 6 deletions
|
@ -19,6 +19,14 @@
|
|||
class AnnotationStorage {
|
||||
constructor() {
|
||||
this._storage = new Map();
|
||||
this._modified = false;
|
||||
|
||||
// Callbacks to signal when the modification state is set or reset.
|
||||
// This is used by the viewer to only bind on `beforeunload` if forms
|
||||
// are actually edited to prevent doing so unconditionally since that
|
||||
// can have undesirable efffects.
|
||||
this.onSetModified = null;
|
||||
this.onResetModified = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,6 +57,9 @@ class AnnotationStorage {
|
|||
* @param {Object} value
|
||||
*/
|
||||
setValue(key, value) {
|
||||
if (this._storage.get(key) !== value) {
|
||||
this.setModified();
|
||||
}
|
||||
this._storage.set(key, value);
|
||||
}
|
||||
|
||||
|
@ -62,6 +73,24 @@ class AnnotationStorage {
|
|||
get size() {
|
||||
return this._storage.size;
|
||||
}
|
||||
|
||||
setModified() {
|
||||
if (!this._modified) {
|
||||
this._modified = true;
|
||||
if (typeof this.onSetModified === "function") {
|
||||
this.onSetModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resetModified() {
|
||||
if (this._modified) {
|
||||
this._modified = false;
|
||||
if (typeof this.onResetModified === "function") {
|
||||
this.onResetModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { AnnotationStorage };
|
||||
|
|
|
@ -2536,12 +2536,16 @@ class WorkerTransport {
|
|||
}
|
||||
|
||||
saveDocument(annotationStorage) {
|
||||
return this.messageHandler.sendWithPromise("SaveDocument", {
|
||||
numPages: this._numPages,
|
||||
annotationStorage:
|
||||
(annotationStorage && annotationStorage.getAll()) || null,
|
||||
filename: this._fullReader.filename,
|
||||
});
|
||||
return this.messageHandler
|
||||
.sendWithPromise("SaveDocument", {
|
||||
numPages: this._numPages,
|
||||
annotationStorage:
|
||||
(annotationStorage && annotationStorage.getAll()) || null,
|
||||
filename: this._fullReader.filename,
|
||||
})
|
||||
.finally(() => {
|
||||
annotationStorage.resetModified();
|
||||
});
|
||||
}
|
||||
|
||||
getDestinations() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue