fix pagerendered callback with new pdf.js
This commit is contained in:
parent
423271ca55
commit
3edf3846a5
1 changed files with 15 additions and 6 deletions
|
@ -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)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue