From d97d396ef306a4bba9ab156f470c9db6d435d4d0 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 25 Jan 2019 16:38:45 +0530 Subject: [PATCH] scroll select annotation into view --- static/reader/pdf.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/static/reader/pdf.js b/static/reader/pdf.js index 6e095f1..15b4487 100644 --- a/static/reader/pdf.js +++ b/static/reader/pdf.js @@ -11,14 +11,21 @@ Ox.load({ console.log('got', event, 'data', data) if (event == 'selectAnnotation') { var annotation = annotations.filter(function(a) { return a.id == data.id })[0] + var delay = 0 if ( annotation && annotation.page && PDFViewerApplication.pdfViewer.currentPageNumber != annotation.page ) { - //FIXME: scroll into view PDFViewerApplication.pdfViewer.currentPageNumber = annotation.page; + delay = 250 } + setTimeout(function() { + var el = document.querySelector('.a' + annotation.id); + if (el) { + document.querySelector('#viewerContainer').scrollTop = el.offsetTop + el.parentElement.offsetTop - 64; + } + }, delay) selectAnnotation(data.id) } else if (event == 'addAnnotations') { data.annotations.forEach(function(annotation) {