From 497c2bb6bed77f5b0212f174698acab08f781bb3 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 9 Feb 2019 17:13:00 +0530 Subject: [PATCH] add position --- static/reader/epub.js | 13 ++++++++++--- static/reader/pdf.js | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/static/reader/epub.js b/static/reader/epub.js index ae870b9..bc5b491 100644 --- a/static/reader/epub.js +++ b/static/reader/epub.js @@ -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 } diff --git a/static/reader/pdf.js b/static/reader/pdf.js index 1e4b003..bb5af83 100644 --- a/static/reader/pdf.js +++ b/static/reader/pdf.js @@ -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))