store annotations in db and sync with peers
This commit is contained in:
parent
131a6a3215
commit
e0cba14d6a
21 changed files with 385 additions and 63 deletions
|
|
@ -22,6 +22,12 @@ Ox.load({
|
|||
} else if (event == 'addAnnotation') {
|
||||
createAnnotation()
|
||||
} else if (event == 'addAnnotations') {
|
||||
if (data.replace) {
|
||||
annotations.forEach(function(a) {
|
||||
reader.rendition.annotations.remove(a.cfiRange)
|
||||
})
|
||||
annotations = []
|
||||
}
|
||||
data.annotations.forEach(function(annotation) {
|
||||
annotations.push(annotation)
|
||||
renderAnnotation(annotation)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ Ox.load({
|
|||
}
|
||||
}, function() {
|
||||
Ox.$parent.bindMessage(function(data, event) {
|
||||
console.log('got', event, 'data', data)
|
||||
if (event == 'selectAnnotation') {
|
||||
var annotation = annotations.filter(function(a) { return a.id == data.id })[0]
|
||||
var delay = 0
|
||||
|
|
@ -20,7 +19,7 @@ Ox.load({
|
|||
PDFViewerApplication.pdfViewer.currentPageNumber = annotation.page;
|
||||
delay = 250
|
||||
}
|
||||
setTimeout(function() {
|
||||
annotation && setTimeout(function() {
|
||||
var el = document.querySelector('.a' + annotation.id);
|
||||
if (el && !isInView(el)) {
|
||||
document.querySelector('#viewerContainer').scrollTop = el.offsetTop + el.parentElement.offsetTop - 64;
|
||||
|
|
@ -30,12 +29,20 @@ Ox.load({
|
|||
} else if (event == 'addAnnotation') {
|
||||
createAnnotation()
|
||||
} else if (event == 'addAnnotations') {
|
||||
if (data.replace) {
|
||||
document.querySelectorAll('.oml-annotation').forEach(function(a) {
|
||||
a.remove()
|
||||
})
|
||||
annotations = []
|
||||
}
|
||||
data.annotations.forEach(function(annotation) {
|
||||
annotations.push(annotation)
|
||||
renderAnnotation(annotation)
|
||||
})
|
||||
} else if (event == 'removeAnnotation') {
|
||||
removeAnnotation(data.id)
|
||||
} else {
|
||||
console.log('got', event, 'data', data)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
@ -96,6 +103,7 @@ function getHighlight() {
|
|||
var position = [pageNumber].concat(Ox.sort(selected.map(function(c) { return [c[1], c[0]]}))[0]);
|
||||
return {
|
||||
page: pageNumber,
|
||||
pageLabel: PDFViewerApplication.pdfViewer.currentPageLabel,
|
||||
position: position,
|
||||
coords: selected,
|
||||
text: text,
|
||||
|
|
@ -176,7 +184,7 @@ function deselectAllAnnotations() {
|
|||
g.classList.remove('selected')
|
||||
g.style.backgroundColor = 'yellow'
|
||||
var id = $(g).parents('.oml-annotation').data('id')
|
||||
console.log('deselect', g, id)
|
||||
//console.log('deselect', g, id)
|
||||
if (!Ox.contains(ids, id)) {
|
||||
ids.push(id)
|
||||
Ox.$parent.postMessage('selectAnnotation', {id: null})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue