add annotation event from annotation panel
This commit is contained in:
parent
fedd0c7e80
commit
fe9b0618ed
4 changed files with 72 additions and 24 deletions
|
@ -10,6 +10,10 @@ oml.ui.annotationPanel = function() {
|
||||||
title: 'add',
|
title: 'add',
|
||||||
tooltip: Ox._('Add Quote'),
|
tooltip: Ox._('Add Quote'),
|
||||||
type: 'image'
|
type: 'image'
|
||||||
|
}).bindEvent({
|
||||||
|
click: function() {
|
||||||
|
oml.$ui.viewer.postMessage('addAnnotation', {})
|
||||||
|
}
|
||||||
}).appendTo($bar);
|
}).appendTo($bar);
|
||||||
|
|
||||||
var $menuButton = Ox.MenuButton({
|
var $menuButton = Ox.MenuButton({
|
||||||
|
@ -50,6 +54,12 @@ oml.ui.annotationPanel = function() {
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
that.updateSelection = function(selection) {
|
||||||
|
$button.options({
|
||||||
|
disabled: !selection
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -110,6 +110,8 @@ oml.ui.viewer = function() {
|
||||||
} else if (event == 'deselectAnnotation') {
|
} else if (event == 'deselectAnnotation') {
|
||||||
var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)[0]
|
var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)[0]
|
||||||
$annotation && $annotation.deselect()
|
$annotation && $annotation.deselect()
|
||||||
|
} else if (event == 'selection') {
|
||||||
|
oml.$ui.annotationPanel.updateSelection(data)
|
||||||
} else {
|
} else {
|
||||||
console.log('got', event, data)
|
console.log('got', event, data)
|
||||||
that.triggerEvent(event, data);
|
that.triggerEvent(event, data);
|
||||||
|
|
|
@ -18,6 +18,8 @@ Ox.load({
|
||||||
if (annotation) {
|
if (annotation) {
|
||||||
reader.rendition.display(annotation.cfiRange)
|
reader.rendition.display(annotation.cfiRange)
|
||||||
}
|
}
|
||||||
|
} else if (event == 'addAnnotation') {
|
||||||
|
createAnnotation()
|
||||||
} else if (event == 'addAnnotations') {
|
} else if (event == 'addAnnotations') {
|
||||||
data.annotations.forEach(function(annotation) {
|
data.annotations.forEach(function(annotation) {
|
||||||
annotations.push(annotation)
|
annotations.push(annotation)
|
||||||
|
@ -29,6 +31,29 @@ Ox.load({
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
function createAnnotation() {
|
||||||
|
console.log('createAnnotation', currentSelection)
|
||||||
|
if (currentSelection) {
|
||||||
|
/*
|
||||||
|
var range = currentSelection.contents.window.getSelection().getRangeAt(0)
|
||||||
|
console.log(
|
||||||
|
currentSelection.cfiRange,
|
||||||
|
reader.rendition.book.section().cfiFromRange(range).toString()
|
||||||
|
)
|
||||||
|
//currentSelection.cfiRange = reader.rendition.book.section().cfiFromRange(range).toString()
|
||||||
|
*/
|
||||||
|
renderAnnotation(currentSelection)
|
||||||
|
currentSelection.contents.window.getSelection().removeAllRanges();
|
||||||
|
delete currentSelection.contents
|
||||||
|
addAnnotation(currentSelection)
|
||||||
|
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
||||||
|
other.classList.remove('selected')
|
||||||
|
})
|
||||||
|
currentSelection = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function addAnnotation(annotation) {
|
function addAnnotation(annotation) {
|
||||||
annotations.push(annotation)
|
annotations.push(annotation)
|
||||||
Ox.$parent.postMessage('addAnnotation', annotation)
|
Ox.$parent.postMessage('addAnnotation', annotation)
|
||||||
|
@ -125,22 +150,7 @@ document.onreadystatechange = function () {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
deselectAllAnnotations()
|
deselectAllAnnotations()
|
||||||
}
|
}
|
||||||
/*
|
createAnnotation()
|
||||||
var range = currentSelection.contents.window.getSelection().getRangeAt(0)
|
|
||||||
console.log(
|
|
||||||
currentSelection.cfiRange,
|
|
||||||
reader.rendition.book.section().cfiFromRange(range).toString()
|
|
||||||
)
|
|
||||||
//currentSelection.cfiRange = reader.rendition.book.section().cfiFromRange(range).toString()
|
|
||||||
*/
|
|
||||||
renderAnnotation(currentSelection)
|
|
||||||
currentSelection.contents.window.getSelection().removeAllRanges();
|
|
||||||
delete currentSelection.contents
|
|
||||||
addAnnotation(currentSelection)
|
|
||||||
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
|
||||||
other.classList.remove('selected')
|
|
||||||
})
|
|
||||||
currentSelection = null
|
|
||||||
} else if (selected) {
|
} else if (selected) {
|
||||||
console.log('editNote?', selected.dataset.id)
|
console.log('editNote?', selected.dataset.id)
|
||||||
|
|
||||||
|
@ -162,7 +172,16 @@ document.onreadystatechange = function () {
|
||||||
localStorage.epubFontSize = fontSize
|
localStorage.epubFontSize = fontSize
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
console.log(fontSize)
|
}).on('mouseup', function(event) {
|
||||||
|
if (currentSelection) {
|
||||||
|
var selection = window.getSelection()
|
||||||
|
if (selection.isCollapsed) {
|
||||||
|
currentSelection = null
|
||||||
|
}
|
||||||
|
if (!currentSelection) {
|
||||||
|
Ox.$parent.postMessage('selection', false)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
rendition.on("mark", function(cfiRange, contents) {
|
rendition.on("mark", function(cfiRange, contents) {
|
||||||
console.log('!! mark', cfiRange)
|
console.log('!! mark', cfiRange)
|
||||||
|
@ -175,6 +194,7 @@ document.onreadystatechange = function () {
|
||||||
text: text,
|
text: text,
|
||||||
contents: contents
|
contents: contents
|
||||||
}
|
}
|
||||||
|
Ox.$parent.postMessage('selection', text ? true : false)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ Ox.load({
|
||||||
}
|
}
|
||||||
}, delay)
|
}, delay)
|
||||||
selectAnnotation(data.id)
|
selectAnnotation(data.id)
|
||||||
|
} else if (event == 'addAnnotation') {
|
||||||
|
createAnnotation()
|
||||||
} else if (event == 'addAnnotations') {
|
} else if (event == 'addAnnotations') {
|
||||||
data.annotations.forEach(function(annotation) {
|
data.annotations.forEach(function(annotation) {
|
||||||
annotations.push(annotation)
|
annotations.push(annotation)
|
||||||
|
@ -47,13 +49,7 @@ window.addEventListener('keydown', function(event) {
|
||||||
} else if (event.key == 'n' || event.keyCode == 13) {
|
} else if (event.key == 'n' || event.keyCode == 13) {
|
||||||
var selected = document.querySelector('.oml-annotation.selected')
|
var selected = document.querySelector('.oml-annotation.selected')
|
||||||
if (!window.getSelection().isCollapsed) {
|
if (!window.getSelection().isCollapsed) {
|
||||||
if (selected) {
|
createAnnotation()
|
||||||
deselectAllAnnotations()
|
|
||||||
}
|
|
||||||
var annot = getHighlight()
|
|
||||||
renderAnnotation(annot)
|
|
||||||
addAnnotation(annot)
|
|
||||||
window.getSelection().removeAllRanges();
|
|
||||||
} else if (selected) {
|
} else if (selected) {
|
||||||
console.log('editNote?', selected.dataset.id)
|
console.log('editNote?', selected.dataset.id)
|
||||||
}
|
}
|
||||||
|
@ -61,6 +57,14 @@ window.addEventListener('keydown', function(event) {
|
||||||
event.preventDefault()
|
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() {
|
function bindEvents() {
|
||||||
if (!window.PDFViewerApplication || !window.PDFViewerApplication.eventBus) {
|
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) {
|
function renderAnnotation(annotation) {
|
||||||
var pageIndex = annotation.page - 1;
|
var pageIndex = annotation.page - 1;
|
||||||
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
||||||
|
|
Loading…
Reference in a new issue