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) {
loadAnnotations(event.detail.pageNumber - 1)
function bindEvents() {
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() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
@ -112,12 +121,12 @@ function saveAnnotations() {
localStorage[id + '.annotations'] = JSON.stringify(annotations)
}
function loadAnnotations(page) {
document.querySelectorAll('.oml-annotation.page' + page).forEach(function(e) {
function loadAnnotations(pageIndex) {
document.querySelectorAll('.oml-annotation.page' + pageIndex).forEach(function(e) {
e.remove()
})
annotations.filter(function(a) {
return a.page == page
return a.page == pageIndex
}).forEach(function(annot) {
renderAnnotation(annot)
})