add position
This commit is contained in:
parent
81e943625d
commit
497c2bb6be
2 changed files with 12 additions and 3 deletions
|
@ -4,6 +4,7 @@ var id = document.location.pathname.split('/')[1];
|
||||||
var annotations = [];
|
var annotations = [];
|
||||||
var currentSelection;
|
var currentSelection;
|
||||||
var fontSize = parseInt(localStorage.epubFontSize || '100', 10)
|
var fontSize = parseInt(localStorage.epubFontSize || '100', 10)
|
||||||
|
var justSelected = false;
|
||||||
|
|
||||||
Ox.load({
|
Ox.load({
|
||||||
'UI': {
|
'UI': {
|
||||||
|
@ -50,6 +51,7 @@ function createAnnotation() {
|
||||||
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
document.querySelectorAll('.epubjs-hl.selected').forEach(function(other) {
|
||||||
other.classList.remove('selected')
|
other.classList.remove('selected')
|
||||||
})
|
})
|
||||||
|
console.log('create annot')
|
||||||
currentSelection = null
|
currentSelection = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,6 +146,8 @@ document.onreadystatechange = function () {
|
||||||
}
|
}
|
||||||
if (event.key == 'n' || event.keyCode == 13) {
|
if (event.key == 'n' || event.keyCode == 13) {
|
||||||
var selected = document.querySelector('.epubjs-hl.selected')
|
var selected = document.querySelector('.epubjs-hl.selected')
|
||||||
|
console.log('!!', currentSelection, selected)
|
||||||
|
|
||||||
if (currentSelection) {
|
if (currentSelection) {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
deselectAllAnnotations()
|
deselectAllAnnotations()
|
||||||
|
@ -151,7 +155,6 @@ document.onreadystatechange = function () {
|
||||||
createAnnotation()
|
createAnnotation()
|
||||||
} else if (selected) {
|
} else if (selected) {
|
||||||
console.log('editNote?', selected.dataset.id)
|
console.log('editNote?', selected.dataset.id)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.keyCode == 61 && event.shiftKey) {
|
if (event.keyCode == 61 && event.shiftKey) {
|
||||||
|
@ -171,8 +174,7 @@ document.onreadystatechange = function () {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
}).on('mouseup', function(event) {
|
}).on('mouseup', function(event) {
|
||||||
if (currentSelection) {
|
if (!justSelected) {
|
||||||
deselectAllAnnotations()
|
|
||||||
var selection = window.getSelection()
|
var selection = window.getSelection()
|
||||||
if (selection.isCollapsed) {
|
if (selection.isCollapsed) {
|
||||||
currentSelection = null
|
currentSelection = null
|
||||||
|
@ -181,15 +183,20 @@ document.onreadystatechange = function () {
|
||||||
Ox.$parent.postMessage('selectText', false)
|
Ox.$parent.postMessage('selectText', false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
deselectAllAnnotations()
|
||||||
|
justSelected = false
|
||||||
})
|
})
|
||||||
rendition.on("mark", function(cfiRange, contents) {
|
rendition.on("mark", function(cfiRange, contents) {
|
||||||
console.log('!! mark', cfiRange)
|
console.log('!! mark', cfiRange)
|
||||||
})
|
})
|
||||||
rendition.on("selected", function(cfiRange, contents) {
|
rendition.on("selected", function(cfiRange, contents) {
|
||||||
|
justSelected = true
|
||||||
getText(book, cfiRange, function(text) {
|
getText(book, cfiRange, function(text) {
|
||||||
|
var position = cfiRange;
|
||||||
currentSelection = {
|
currentSelection = {
|
||||||
id: Ox.SHA1(cfiRange),
|
id: Ox.SHA1(cfiRange),
|
||||||
cfiRange: cfiRange,
|
cfiRange: cfiRange,
|
||||||
|
position: position,
|
||||||
text: text,
|
text: text,
|
||||||
contents: contents
|
contents: contents
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,8 +91,10 @@ function getHighlight() {
|
||||||
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
|
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
|
||||||
});
|
});
|
||||||
var text = selection.toString();
|
var text = selection.toString();
|
||||||
|
var position = [pageNumber].concat(Ox.sort(selected.coords.map(function(c) { return [c[1], c[0]]}))[0]);
|
||||||
return {
|
return {
|
||||||
page: pageNumber,
|
page: pageNumber,
|
||||||
|
position: position,
|
||||||
coords: selected,
|
coords: selected,
|
||||||
text: text,
|
text: text,
|
||||||
id: Ox.SHA1(pageNumber.toString() + JSON.stringify(selected))
|
id: Ox.SHA1(pageNumber.toString() + JSON.stringify(selected))
|
||||||
|
|
Loading…
Reference in a new issue