fix pagerendered callback with new pdf.js

This commit is contained in:
j 2019-01-23 14:44:36 +05:30
parent 423271ca55
commit 3edf3846a5

View file

@ -30,9 +30,18 @@ window.addEventListener('keydown', function(event) {
} }
}) })
window.addEventListener('pagerendered', function (event) { function bindEvents() {
loadAnnotations(event.detail.pageNumber - 1) if (!window.PDFViewerApplication || !window.PDFViewerApplication.eventBus) {
}) setTimeout(bindEvents, 10)
return
}
PDFViewerApplication.eventBus.on('pagerendered', function(event) {
var pageIndex = event.pageNumber - 1
loadAnnotations(pageIndex)
})
}
bindEvents()
function getHighlight() { function getHighlight() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1; var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
@ -112,12 +121,12 @@ function saveAnnotations() {
localStorage[id + '.annotations'] = JSON.stringify(annotations) localStorage[id + '.annotations'] = JSON.stringify(annotations)
} }
function loadAnnotations(page) { function loadAnnotations(pageIndex) {
document.querySelectorAll('.oml-annotation.page' + page).forEach(function(e) { document.querySelectorAll('.oml-annotation.page' + pageIndex).forEach(function(e) {
e.remove() e.remove()
}) })
annotations.filter(function(a) { annotations.filter(function(a) {
return a.page == page return a.page == pageIndex
}).forEach(function(annot) { }).forEach(function(annot) {
renderAnnotation(annot) renderAnnotation(annot)
}) })