mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-07 17:05:38 +02:00
Simplify the PDFDocumentProperties.#updateUI
method
We can remove the `reset`-parameter, since it's redundant, given that it's only used after `PDFDocumentProperties.#reset` has been invoked which means that `this.#fieldData === null` which is equivalent to resetting. Also, we don't need to have two separate loops in order to update the UI in this method. Finally, inline the `DEFAULT_FIELD_CONTENT` constant now that it's only used once.
This commit is contained in:
parent
ab052db5b3
commit
a5d0e410c7
1 changed files with 8 additions and 16 deletions
|
@ -22,8 +22,6 @@
|
||||||
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
|
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
|
||||||
import { PDFDateString } from "pdfjs-lib";
|
import { PDFDateString } from "pdfjs-lib";
|
||||||
|
|
||||||
const DEFAULT_FIELD_CONTENT = "-";
|
|
||||||
|
|
||||||
// See https://en.wikibooks.org/wiki/Lentis/Conversion_to_the_Metric_Standard_in_the_United_States
|
// See https://en.wikibooks.org/wiki/Lentis/Conversion_to_the_Metric_Standard_in_the_United_States
|
||||||
const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
|
const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
|
||||||
|
|
||||||
|
@ -192,7 +190,7 @@ class PDFDocumentProperties {
|
||||||
setDocument(pdfDocument) {
|
setDocument(pdfDocument) {
|
||||||
if (this.pdfDocument) {
|
if (this.pdfDocument) {
|
||||||
this.#reset();
|
this.#reset();
|
||||||
this.#updateUI(true);
|
this.#updateUI();
|
||||||
}
|
}
|
||||||
if (!pdfDocument) {
|
if (!pdfDocument) {
|
||||||
return;
|
return;
|
||||||
|
@ -214,24 +212,18 @@ class PDFDocumentProperties {
|
||||||
/**
|
/**
|
||||||
* Always updates all of the dialog fields, to prevent inconsistent UI state.
|
* Always updates all of the dialog fields, to prevent inconsistent UI state.
|
||||||
* NOTE: If the contents of a particular field is neither a non-empty string,
|
* NOTE: If the contents of a particular field is neither a non-empty string,
|
||||||
* nor a number, it will fall back to `DEFAULT_FIELD_CONTENT`.
|
* nor a number, it will fall back to "-".
|
||||||
*/
|
*/
|
||||||
#updateUI(reset = false) {
|
#updateUI() {
|
||||||
if (reset || !this.#fieldData) {
|
if (this.#fieldData && this.overlayManager.active !== this.dialog) {
|
||||||
for (const id in this.fields) {
|
// Don't bother updating the dialog if it's already been closed,
|
||||||
this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
|
// unless it's being reset (i.e. `this.#fieldData === null`),
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.overlayManager.active !== this.dialog) {
|
|
||||||
// Don't bother updating the dialog if has already been closed,
|
|
||||||
// since it will be updated the next time `this.open` is called.
|
// since it will be updated the next time `this.open` is called.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const id in this.fields) {
|
for (const id in this.fields) {
|
||||||
const content = this.#fieldData[id];
|
const content = this.#fieldData?.[id];
|
||||||
this.fields[id].textContent =
|
this.fields[id].textContent = content || content === 0 ? content : "-";
|
||||||
content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue