|
@@ -35,6 +35,7 @@ var _pdf_thumbnail_view = require('./pdf_thumbnail_view');
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
|
|
var THUMBNAIL_SCROLL_MARGIN = -19;
|
|
|
+var THUMBNAIL_SELECTED_CLASS = 'selected';
|
|
|
|
|
|
var PDFThumbnailViewer = function () {
|
|
|
function PDFThumbnailViewer(_ref) {
|
|
@@ -71,14 +72,19 @@ var PDFThumbnailViewer = function () {
|
|
|
}
|
|
|
}, {
|
|
|
key: 'scrollThumbnailIntoView',
|
|
|
- value: function scrollThumbnailIntoView(page) {
|
|
|
- var selected = document.querySelector('.thumbnail.selected');
|
|
|
- if (selected) {
|
|
|
- selected.classList.remove('selected');
|
|
|
+ value: function scrollThumbnailIntoView(pageNumber) {
|
|
|
+ if (!this.pdfDocument) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var thumbnailView = this._thumbnails[pageNumber - 1];
|
|
|
+ if (!thumbnailView) {
|
|
|
+ console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
|
|
|
+ return;
|
|
|
}
|
|
|
- var thumbnail = document.querySelector('div.thumbnail[data-page-number="' + page + '"]');
|
|
|
- if (thumbnail) {
|
|
|
- thumbnail.classList.add('selected');
|
|
|
+ if (pageNumber !== this._currentPageNumber) {
|
|
|
+ var prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
|
|
+ prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
|
|
|
+ thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
|
}
|
|
|
var visibleThumbs = this._getVisibleThumbs();
|
|
|
var numVisibleThumbs = visibleThumbs.views.length;
|
|
@@ -86,11 +92,11 @@ var PDFThumbnailViewer = function () {
|
|
|
var first = visibleThumbs.first.id;
|
|
|
var last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
|
|
|
var shouldScroll = false;
|
|
|
- if (page <= first || page >= last) {
|
|
|
+ if (pageNumber <= first || pageNumber >= last) {
|
|
|
shouldScroll = true;
|
|
|
} else {
|
|
|
visibleThumbs.views.some(function (view) {
|
|
|
- if (view.id !== page) {
|
|
|
+ if (view.id !== pageNumber) {
|
|
|
return false;
|
|
|
}
|
|
|
shouldScroll = view.percent < 100;
|
|
@@ -98,9 +104,10 @@ var PDFThumbnailViewer = function () {
|
|
|
});
|
|
|
}
|
|
|
if (shouldScroll) {
|
|
|
- (0, _ui_utils.scrollIntoView)(thumbnail, { top: THUMBNAIL_SCROLL_MARGIN });
|
|
|
+ (0, _ui_utils.scrollIntoView)(thumbnailView.div, { top: THUMBNAIL_SCROLL_MARGIN });
|
|
|
}
|
|
|
}
|
|
|
+ this._currentPageNumber = pageNumber;
|
|
|
}
|
|
|
}, {
|
|
|
key: 'cleanup',
|
|
@@ -111,6 +118,7 @@ var PDFThumbnailViewer = function () {
|
|
|
key: '_resetView',
|
|
|
value: function _resetView() {
|
|
|
this._thumbnails = [];
|
|
|
+ this._currentPageNumber = 1;
|
|
|
this._pageLabels = null;
|
|
|
this._pagesRotation = 0;
|
|
|
this._pagesRequests = [];
|
|
@@ -144,6 +152,8 @@ var PDFThumbnailViewer = function () {
|
|
|
});
|
|
|
_this._thumbnails.push(thumbnail);
|
|
|
}
|
|
|
+ var thumbnailView = _this._thumbnails[_this._currentPageNumber - 1];
|
|
|
+ thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
|
}).catch(function (reason) {
|
|
|
console.error('Unable to initialize thumbnail viewer', reason);
|
|
|
});
|