Add helper functions to reduce unnecessary duplication when fetching l10n messages in PDFThumbnailView

This commit is contained in:
Jonas Jenwald 2020-01-11 14:28:29 +01:00
parent 16a94412e4
commit 34e7d42ce6

View File

@ -125,9 +125,7 @@ class PDFThumbnailView {
const anchor = document.createElement("a");
anchor.href = linkService.getAnchorUrl("#page=" + id);
this.l10n
.get("thumb_page_title", { page: id }, "Page {{page}}")
.then(msg => {
this._thumbPageTitle.then(msg => {
anchor.title = msg;
});
anchor.onclick = function() {
@ -262,13 +260,7 @@ class PDFThumbnailView {
if (this.disableCanvasToImageConversion) {
this.canvas.className = className;
this.l10n
.get(
"thumb_page_canvas",
{ page: this.pageId },
"Thumbnail of Page {{page}}"
)
.then(msg => {
this._thumbPageCanvas.then(msg => {
this.canvas.setAttribute("aria-label", msg);
});
@ -278,13 +270,7 @@ class PDFThumbnailView {
}
const image = document.createElement("img");
image.className = className;
this.l10n
.get(
"thumb_page_canvas",
{ page: this.pageId },
"Thumbnail of Page {{page}}"
)
.then(msg => {
this._thumbPageCanvas.then(msg => {
image.setAttribute("aria-label", msg);
});
@ -452,8 +438,20 @@ class PDFThumbnailView {
this._convertCanvasToImage();
}
get pageId() {
return this.pageLabel !== null ? this.pageLabel : this.id;
get _thumbPageTitle() {
return this.l10n.get(
"thumb_page_title",
{ page: this.pageLabel !== null ? this.pageLabel : this.id },
"Page {{page}}"
);
}
get _thumbPageCanvas() {
return this.l10n.get(
"thumb_page_canvas",
{ page: this.pageLabel !== null ? this.pageLabel : this.id },
"Thumbnail of Page {{page}}"
);
}
/**
@ -462,9 +460,7 @@ class PDFThumbnailView {
setPageLabel(label) {
this.pageLabel = typeof label === "string" ? label : null;
this.l10n
.get("thumb_page_title", { page: this.pageId }, "Page {{page}}")
.then(msg => {
this._thumbPageTitle.then(msg => {
this.anchor.title = msg;
});
@ -472,17 +468,11 @@ class PDFThumbnailView {
return;
}
this.l10n
.get(
"thumb_page_canvas",
{ page: this.pageId },
"Thumbnail of Page {{page}}"
)
.then(ariaLabel => {
this._thumbPageCanvas.then(msg => {
if (this.image) {
this.image.setAttribute("aria-label", ariaLabel);
this.image.setAttribute("aria-label", msg);
} else if (this.disableCanvasToImageConversion && this.canvas) {
this.canvas.setAttribute("aria-label", ariaLabel);
this.canvas.setAttribute("aria-label", msg);
}
});
}