add position

This commit is contained in:
j 2019-02-09 17:13:00 +05:30
parent 81e943625d
commit 497c2bb6be
2 changed files with 12 additions and 3 deletions

View file

@ -4,6 +4,7 @@ var id = document.location.pathname.split('/')[1];
var annotations = [];
var currentSelection;
var fontSize = parseInt(localStorage.epubFontSize || '100', 10)
var justSelected = false;
Ox.load({
'UI': {
@ -50,6 +51,7 @@ function createAnnotation() {
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
other.classList.remove('selected')
})
console.log('create annot')
currentSelection = null
}
}
@ -144,6 +146,8 @@ document.onreadystatechange = function () {
}
if (event.key == 'n' || event.keyCode == 13) {
var selected = document.querySelector('.epubjs-hl.selected')
console.log('!!', currentSelection, selected)
if (currentSelection) {
if (selected) {
deselectAllAnnotations()
@ -151,7 +155,6 @@ document.onreadystatechange = function () {
createAnnotation()
} else if (selected) {
console.log('editNote?', selected.dataset.id)
}
}
if (event.keyCode == 61 && event.shiftKey) {
@ -171,8 +174,7 @@ document.onreadystatechange = function () {
event.preventDefault()
}
}).on('mouseup', function(event) {
if (currentSelection) {
deselectAllAnnotations()
if (!justSelected) {
var selection = window.getSelection()
if (selection.isCollapsed) {
currentSelection = null
@ -181,15 +183,20 @@ document.onreadystatechange = function () {
Ox.$parent.postMessage('selectText', false)
}
}
deselectAllAnnotations()
justSelected = false
})
rendition.on("mark", function(cfiRange, contents) {
console.log('!! mark', cfiRange)
})
rendition.on("selected", function(cfiRange, contents) {
justSelected = true
getText(book, cfiRange, function(text) {
var position = cfiRange;
currentSelection = {
id: Ox.SHA1(cfiRange),
cfiRange: cfiRange,
position: position,
text: text,
contents: contents
}

View file

@ -91,8 +91,10 @@ function getHighlight() {
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
});
var text = selection.toString();
var position = [pageNumber].concat(Ox.sort(selected.coords.map(function(c) { return [c[1], c[0]]}))[0]);
return {
page: pageNumber,
position: position,
coords: selected,
text: text,
id: Ox.SHA1(pageNumber.toString() + JSON.stringify(selected))