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,11 +125,9 @@ class PDFThumbnailView {
const anchor = document.createElement("a"); const anchor = document.createElement("a");
anchor.href = linkService.getAnchorUrl("#page=" + id); anchor.href = linkService.getAnchorUrl("#page=" + id);
this.l10n this._thumbPageTitle.then(msg => {
.get("thumb_page_title", { page: id }, "Page {{page}}") anchor.title = msg;
.then(msg => { });
anchor.title = msg;
});
anchor.onclick = function() { anchor.onclick = function() {
linkService.page = id; linkService.page = id;
return false; return false;
@ -262,15 +260,9 @@ class PDFThumbnailView {
if (this.disableCanvasToImageConversion) { if (this.disableCanvasToImageConversion) {
this.canvas.className = className; this.canvas.className = className;
this.l10n this._thumbPageCanvas.then(msg => {
.get( this.canvas.setAttribute("aria-label", msg);
"thumb_page_canvas", });
{ page: this.pageId },
"Thumbnail of Page {{page}}"
)
.then(msg => {
this.canvas.setAttribute("aria-label", msg);
});
this.div.setAttribute("data-loaded", true); this.div.setAttribute("data-loaded", true);
this.ring.appendChild(this.canvas); this.ring.appendChild(this.canvas);
@ -278,15 +270,9 @@ class PDFThumbnailView {
} }
const image = document.createElement("img"); const image = document.createElement("img");
image.className = className; image.className = className;
this.l10n this._thumbPageCanvas.then(msg => {
.get( image.setAttribute("aria-label", msg);
"thumb_page_canvas", });
{ page: this.pageId },
"Thumbnail of Page {{page}}"
)
.then(msg => {
image.setAttribute("aria-label", msg);
});
image.style.width = this.canvasWidth + "px"; image.style.width = this.canvasWidth + "px";
image.style.height = this.canvasHeight + "px"; image.style.height = this.canvasHeight + "px";
@ -452,8 +438,20 @@ class PDFThumbnailView {
this._convertCanvasToImage(); this._convertCanvasToImage();
} }
get pageId() { get _thumbPageTitle() {
return this.pageLabel !== null ? this.pageLabel : this.id; 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,29 +460,21 @@ class PDFThumbnailView {
setPageLabel(label) { setPageLabel(label) {
this.pageLabel = typeof label === "string" ? label : null; this.pageLabel = typeof label === "string" ? label : null;
this.l10n this._thumbPageTitle.then(msg => {
.get("thumb_page_title", { page: this.pageId }, "Page {{page}}") this.anchor.title = msg;
.then(msg => { });
this.anchor.title = msg;
});
if (this.renderingState !== RenderingStates.FINISHED) { if (this.renderingState !== RenderingStates.FINISHED) {
return; return;
} }
this.l10n this._thumbPageCanvas.then(msg => {
.get( if (this.image) {
"thumb_page_canvas", this.image.setAttribute("aria-label", msg);
{ page: this.pageId }, } else if (this.disableCanvasToImageConversion && this.canvas) {
"Thumbnail of Page {{page}}" this.canvas.setAttribute("aria-label", msg);
) }
.then(ariaLabel => { });
if (this.image) {
this.image.setAttribute("aria-label", ariaLabel);
} else if (this.disableCanvasToImageConversion && this.canvas) {
this.canvas.setAttribute("aria-label", ariaLabel);
}
});
} }
static cleanup() { static cleanup() {