Add PageLabels to PDFPageView
and PDFThumbnailView
This commit is contained in:
parent
f461fd64aa
commit
efb9619e53
@ -78,6 +78,7 @@ var PDFPageView = (function PDFPageViewClosure() {
|
||||
|
||||
this.id = id;
|
||||
this.renderingId = 'page' + id;
|
||||
this.pageLabel = null;
|
||||
|
||||
this.rotation = 0;
|
||||
this.scale = scale || DEFAULT_SCALE;
|
||||
@ -554,6 +555,19 @@ var PDFPageView = (function PDFPageViewClosure() {
|
||||
}
|
||||
return promise;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string|null} label
|
||||
*/
|
||||
setPageLabel: function PDFView_setPageLabel(label) {
|
||||
this.pageLabel = (typeof label === 'string' ? label : null);
|
||||
|
||||
if (this.pageLabel !== null) {
|
||||
this.div.setAttribute('data-page-label', this.pageLabel);
|
||||
} else {
|
||||
this.div.removeAttribute('data-page-label');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return PDFPageView;
|
||||
|
@ -91,6 +91,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
||||
|
||||
this.id = id;
|
||||
this.renderingId = 'thumbnail' + id;
|
||||
this.pageLabel = null;
|
||||
|
||||
this.pdfPage = null;
|
||||
this.rotation = 0;
|
||||
@ -120,6 +121,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
||||
linkService.page = id;
|
||||
return false;
|
||||
};
|
||||
this.anchor = anchor;
|
||||
|
||||
var div = document.createElement('div');
|
||||
div.id = 'thumbnailContainer' + id;
|
||||
@ -247,7 +249,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
||||
}
|
||||
var id = this.renderingId;
|
||||
var className = 'thumbnailImage';
|
||||
var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.id },
|
||||
var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId },
|
||||
'Thumbnail of Page {{page}}');
|
||||
|
||||
if (this.disableCanvasToImageConversion) {
|
||||
@ -395,7 +397,32 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
||||
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight,
|
||||
0, 0, canvas.width, canvas.height);
|
||||
this._convertCanvasToImage();
|
||||
}
|
||||
},
|
||||
|
||||
get pageId() {
|
||||
return (this.pageLabel !== null ? this.pageLabel : this.id);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string|null} label
|
||||
*/
|
||||
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
|
||||
this.pageLabel = (typeof label === 'string' ? label : null);
|
||||
|
||||
this.anchor.title = mozL10n.get('thumb_page_title', { page: this.pageId },
|
||||
'Page {{page}}');
|
||||
|
||||
if (this.renderingState !== RenderingStates.FINISHED) {
|
||||
return;
|
||||
}
|
||||
var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId },
|
||||
'Thumbnail of Page {{page}}');
|
||||
if (this.image) {
|
||||
this.image.setAttribute('aria-label', ariaLabel);
|
||||
} else if (this.disableCanvasToImageConversion && this.canvas) {
|
||||
this.canvas.setAttribute('aria-label', ariaLabel);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return PDFThumbnailView;
|
||||
|
@ -196,6 +196,12 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
|
||||
} else {
|
||||
this._pageLabels = labels;
|
||||
}
|
||||
// Update all the `PDFThumbnailView` instances.
|
||||
for (var i = 0, ii = this.thumbnails.length; i < ii; i++) {
|
||||
var thumbnailView = this.thumbnails[i];
|
||||
var label = this._pageLabels && this._pageLabels[i];
|
||||
thumbnailView.setPageLabel(label);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -453,6 +453,12 @@ var PDFViewer = (function pdfViewer() {
|
||||
} else {
|
||||
this._pageLabels = labels;
|
||||
}
|
||||
// Update all the `PDFPageView` instances.
|
||||
for (var i = 0, ii = this._pages.length; i < ii; i++) {
|
||||
var pageView = this._pages[i];
|
||||
var label = this._pageLabels && this._pageLabels[i];
|
||||
pageView.setPageLabel(label);
|
||||
}
|
||||
},
|
||||
|
||||
_resetView: function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user