unify annotations local storage
This commit is contained in:
parent
3905ddb9fc
commit
d4b89137db
4 changed files with 61 additions and 40 deletions
|
|
@ -1,5 +1,5 @@
|
|||
var id = document.location.pathname.split('/')[1];
|
||||
var annotations = JSON.parse(localStorage[id + '.annotations'] || '[]')
|
||||
var annotations = [];
|
||||
var currentPage = 1, rendered = false
|
||||
|
||||
Ox.load({
|
||||
|
|
@ -20,13 +20,13 @@ Ox.load({
|
|||
PDFViewerApplication.pdfViewer.currentPageNumber = annotation.page;
|
||||
}
|
||||
selectAnnotation(data.id)
|
||||
} else if (event == 'addAnnotations') {
|
||||
data.annotations.forEach(function(annotation) {
|
||||
annotations.push(annotation)
|
||||
renderAnnotation(annotation)
|
||||
})
|
||||
}
|
||||
})
|
||||
setTimeout(function() {
|
||||
annotations.forEach(function(a) {
|
||||
Ox.$parent.postMessage('addAnnotation', a)
|
||||
})
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
window.addEventListener('keydown', function(event) {
|
||||
|
|
@ -34,7 +34,6 @@ window.addEventListener('keydown', function(event) {
|
|||
var selected = document.querySelector('.oml-annotation.selected')
|
||||
if (selected) {
|
||||
removeAnnotation(selected.dataset.id)
|
||||
Ox.$parent.postMessage('removeAnnotation', {id: selected.dataset.id})
|
||||
}
|
||||
} else if (event.key == 'n') {
|
||||
if (!window.getSelection().isCollapsed) {
|
||||
|
|
@ -74,7 +73,6 @@ function getHighlight() {
|
|||
});
|
||||
var text = selection.toString();
|
||||
return {
|
||||
created: (new Date).toISOString(),
|
||||
page: pageNumber,
|
||||
coords: selected,
|
||||
text: text,
|
||||
|
|
@ -85,10 +83,10 @@ function getHighlight() {
|
|||
function renderAnnotation(annotation) {
|
||||
var pageIndex = annotation.page - 1;
|
||||
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
||||
if (!page.canvas) {
|
||||
if (!page || !page.canvas) {
|
||||
setTimeout(function() {
|
||||
renderAnnotation(annotation)
|
||||
}, 10)
|
||||
}, 50)
|
||||
return
|
||||
}
|
||||
var pageElement = page.canvas.parentElement.parentElement;
|
||||
|
|
@ -120,7 +118,6 @@ function renderAnnotation(annotation) {
|
|||
function addAnnotation(annotation) {
|
||||
annotations.push(annotation)
|
||||
Ox.$parent.postMessage('addAnnotation', annotation)
|
||||
saveAnnotations()
|
||||
}
|
||||
|
||||
function selectAnnotation(id) {
|
||||
|
|
@ -147,11 +144,7 @@ function removeAnnotation(id) {
|
|||
annotations = annotations.filter(function(annotation) {
|
||||
return annotation.id != id
|
||||
})
|
||||
saveAnnotations()
|
||||
}
|
||||
|
||||
function saveAnnotations() {
|
||||
localStorage[id + '.annotations'] = JSON.stringify(annotations)
|
||||
Ox.$parent.postMessage('removeAnnotation', {id: selected.dataset.id})
|
||||
}
|
||||
|
||||
function loadAnnotations(page) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue