add annotation event from annotation panel
This commit is contained in:
parent
fedd0c7e80
commit
fe9b0618ed
4 changed files with 72 additions and 24 deletions
|
|
@ -27,6 +27,8 @@ Ox.load({
|
|||
}
|
||||
}, delay)
|
||||
selectAnnotation(data.id)
|
||||
} else if (event == 'addAnnotation') {
|
||||
createAnnotation()
|
||||
} else if (event == 'addAnnotations') {
|
||||
data.annotations.forEach(function(annotation) {
|
||||
annotations.push(annotation)
|
||||
|
|
@ -47,13 +49,7 @@ window.addEventListener('keydown', function(event) {
|
|||
} else if (event.key == 'n' || event.keyCode == 13) {
|
||||
var selected = document.querySelector('.oml-annotation.selected')
|
||||
if (!window.getSelection().isCollapsed) {
|
||||
if (selected) {
|
||||
deselectAllAnnotations()
|
||||
}
|
||||
var annot = getHighlight()
|
||||
renderAnnotation(annot)
|
||||
addAnnotation(annot)
|
||||
window.getSelection().removeAllRanges();
|
||||
createAnnotation()
|
||||
} else if (selected) {
|
||||
console.log('editNote?', selected.dataset.id)
|
||||
}
|
||||
|
|
@ -61,6 +57,14 @@ window.addEventListener('keydown', function(event) {
|
|||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
window.addEventListener('mouseup', function(event) {
|
||||
var selection = window.getSelection()
|
||||
if (selection.isCollapsed) {
|
||||
Ox.$parent.postMessage('selection', false)
|
||||
} else {
|
||||
Ox.$parent.postMessage('selection', true)
|
||||
}
|
||||
})
|
||||
|
||||
function bindEvents() {
|
||||
if (!window.PDFViewerApplication || !window.PDFViewerApplication.eventBus) {
|
||||
|
|
@ -95,6 +99,18 @@ function getHighlight() {
|
|||
};
|
||||
}
|
||||
|
||||
function createAnnotation() {
|
||||
var selected = document.querySelector('.oml-annotation.selected')
|
||||
if (selected) {
|
||||
deselectAllAnnotations()
|
||||
}
|
||||
var annot = getHighlight()
|
||||
renderAnnotation(annot)
|
||||
addAnnotation(annot)
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
|
||||
|
||||
function renderAnnotation(annotation) {
|
||||
var pageIndex = annotation.page - 1;
|
||||
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue