pdf annotations, use n to add annotation for current selection
This commit is contained in:
parent
2fdd070361
commit
8e39b18fe8
3 changed files with 161 additions and 14 deletions
|
|
@ -2,6 +2,7 @@
|
|||
var reader;
|
||||
var id = document.location.pathname.split('/')[1];
|
||||
var annotations = JSON.parse(localStorage[id + '.annotations'] || '[]')
|
||||
var currentSelection;
|
||||
|
||||
function saveAnnotations() {
|
||||
localStorage[id + '.annotations'] = JSON.stringify(annotations)
|
||||
|
|
@ -45,6 +46,7 @@ document.onreadystatechange = function () {
|
|||
rendition.annotations.highlight(a.cfiRange, a.data || {}, onHighlightClicked);
|
||||
})
|
||||
|
||||
|
||||
reader.rendition.on('keydown', function(event) {
|
||||
if (event.key == 'Delete') {
|
||||
document.querySelectorAll('.epubjs-hl.selected').forEach(function(a) {
|
||||
|
|
@ -55,23 +57,43 @@ document.onreadystatechange = function () {
|
|||
saveAnnotations()
|
||||
})
|
||||
}
|
||||
if (event.key == 'n') {
|
||||
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()
|
||||
*/
|
||||
|
||||
rendition.annotations.highlight(currentSelection.cfiRange, currentSelection.data, onHighlightClicked);
|
||||
currentSelection.contents.window.getSelection().removeAllRanges();
|
||||
delete currentSelection.contents
|
||||
annotations.push(currentSelection)
|
||||
saveAnnotations()
|
||||
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
||||
other.classList.remove('selected')
|
||||
})
|
||||
currentSelection = null
|
||||
}
|
||||
}
|
||||
})
|
||||
rendition.on("mark", function(cfiRange, contents) {
|
||||
console.log('!! mark', cfiRange)
|
||||
})
|
||||
rendition.on("selected", function(cfiRange, contents) {
|
||||
console.log('!! selected', cfiRange)
|
||||
getText(book, cfiRange, function(quote) {
|
||||
var data = {
|
||||
quote: quote
|
||||
}
|
||||
rendition.annotations.highlight(cfiRange, data, onHighlightClicked);
|
||||
annotations.push({
|
||||
currentSelection = {
|
||||
cfiRange: cfiRange,
|
||||
data: data
|
||||
})
|
||||
saveAnnotations()
|
||||
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
||||
other.classList.remove('selected')
|
||||
})
|
||||
data: {
|
||||
quote: quote
|
||||
},
|
||||
contents: contents
|
||||
}
|
||||
})
|
||||
contents.window.getSelection().removeAllRanges();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue