diff --git a/static/css/oml.css b/static/css/oml.css index 33ae71b..382cccd 100644 --- a/static/css/oml.css +++ b/static/css/oml.css @@ -9,10 +9,3 @@ .OMLAnnotation.selected .OMLQuote { background-color: rgb(128, 192, 255); } - -.OMLAnnotation .OxPlaceholder { - display: none; -} -.OMLAnnotation.selected .OxPlaceholder { - display: block; -} diff --git a/static/js/annotation.js b/static/js/annotation.js index aeda34a..bf69252 100644 --- a/static/js/annotation.js +++ b/static/js/annotation.js @@ -14,17 +14,21 @@ oml.ui.annotation = function(annotation, $iframe) { var notes = annotation.notes.length ? annotation.notes.map(function(note) { note.editable = !note.user return note - }) : [] - var $notes = Ox.ArrayEditable({ + }) : [{ + id: 'A', + placeholder: 'Add Note', + value: '', + editable: true + }]; + console.log(annotation.notes) + var $note = Ox.ArrayEditable({ editing: true, items: notes, - placeholder: 'Add note', type: 'textarea' }).css({ margin: '2px', minHeight: '12px' }).bindEvent({ - doubleclick: addNote, submit: function(data) { var note = Ox.getObjectById(annotation.notes, data.id) if (note) { @@ -54,26 +58,11 @@ oml.ui.annotation = function(annotation, $iframe) { id: annotation.id }) } - }).append($quote).append($notes); - - - function addNote() { - if (!$notes.options('items').length) { - that.select() - $notes.addItem(0, { - id: 'A', - value: '', - editable: true - }).options({ - selected: 'A' - }).editItem() - } - } - + }).append($quote).append($note); that.annotate = function() { - if (oml.user.ui.showAnnotations) { - addNote() + var item = { + id: 'note', value: '', editable: true } } that.deselect = function() { @@ -81,9 +70,6 @@ oml.ui.annotation = function(annotation, $iframe) { that.loseFocus() } that.select = function () { - $iframe.postMessage('selectAnnotation', { - id: annotation.id - }) let selected = document.querySelector('.OMLAnnotation.selected') selected && selected.classList.remove('selected') that.addClass('selected') diff --git a/static/js/annotationPanel.js b/static/js/annotationPanel.js index ffae227..428afcc 100644 --- a/static/js/annotationPanel.js +++ b/static/js/annotationPanel.js @@ -10,10 +10,6 @@ oml.ui.annotationPanel = function() { title: 'add', tooltip: Ox._('Add Quote'), type: 'image' - }).bindEvent({ - click: function() { - oml.$ui.viewer.postMessage('addAnnotation', {}) - } }).appendTo($bar); var $menuButton = Ox.MenuButton({ @@ -54,12 +50,6 @@ oml.ui.annotationPanel = function() { orientation: 'vertical' }); - that.updateSelection = function(selection) { - $button.options({ - disabled: !selection - }) - } - return that; }; diff --git a/static/js/viewer.js b/static/js/viewer.js index 36ad0d8..98a3598 100644 --- a/static/js/viewer.js +++ b/static/js/viewer.js @@ -95,6 +95,7 @@ oml.ui.viewer = function() { height: '100%', border: 0 }).onMessage(function(data, event) { + console.log('got', event, data) if (event == 'addAnnotation') { console.log('adding', data.id) saveAnnotations(data); @@ -106,14 +107,11 @@ oml.ui.viewer = function() { removeAnnotation(data.id) } else if (event == 'selectAnnotation') { var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id) - $annotation && $annotation.select() + $annotation.select() } else if (event == 'deselectAnnotation') { - var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)[0] - $annotation && $annotation.deselect() - } else if (event == 'selection') { - oml.$ui.annotationPanel.updateSelection(data) + var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id) + $annotation.deselect() } else { - console.log('got', event, data) that.triggerEvent(event, data); } diff --git a/static/reader/epub.js b/static/reader/epub.js index 14a309d..1372628 100644 --- a/static/reader/epub.js +++ b/static/reader/epub.js @@ -18,8 +18,6 @@ Ox.load({ if (annotation) { reader.rendition.display(annotation.cfiRange) } - } else if (event == 'addAnnotation') { - createAnnotation() } else if (event == 'addAnnotations') { data.annotations.forEach(function(annotation) { annotations.push(annotation) @@ -31,29 +29,6 @@ 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) { annotations.push(annotation) Ox.$parent.postMessage('addAnnotation', annotation) @@ -74,18 +49,6 @@ function deselectAnnotation(id) { }) } - -function deselectAllAnnotations() { - var ids = [] - document.querySelectorAll('.epubjs-hl.selected').forEach(function(g) { - g.classList.remove('selected') - if (!Ox.contains(ids, id)) { - ids.push(id) - Ox.$parent.postMessage('deselectAnnotation', {id: id}) - } - }) -} - function removeAnnotation(id) { var a = annotations.filter(function(a) { return a.id == id })[0] if (a) { @@ -120,7 +83,6 @@ function onHighlightClicked(e) { other.classList.remove('selected') }) e.target.classList.add('selected') - Ox.$parent.postMessage('selectAnnotation', {id: e.target.dataset.id}) } } @@ -144,16 +106,24 @@ document.onreadystatechange = function () { removeAnnotation(a.dataset.id) }) } - if (event.key == 'n' || event.keyCode == 13) { - var selected = document.querySelector('.epubjs-hl.selected') + if (event.key == 'n') { if (currentSelection) { - if (selected) { - deselectAllAnnotations() - } - createAnnotation() - } else if (selected) { - console.log('editNote?', selected.dataset.id) - + /* + 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 } } if (event.keyCode == 61 && event.shiftKey) { @@ -172,16 +142,7 @@ document.onreadystatechange = function () { localStorage.epubFontSize = fontSize event.preventDefault() } - }).on('mouseup', function(event) { - if (currentSelection) { - var selection = window.getSelection() - if (selection.isCollapsed) { - currentSelection = null - } - if (!currentSelection) { - Ox.$parent.postMessage('selection', false) - } - } + console.log(fontSize) }) rendition.on("mark", function(cfiRange, contents) { console.log('!! mark', cfiRange) @@ -194,7 +155,6 @@ document.onreadystatechange = function () { text: text, contents: contents } - Ox.$parent.postMessage('selection', text ? true : false) }) }); } diff --git a/static/reader/pdf.js b/static/reader/pdf.js index 164fba9..44ae07b 100644 --- a/static/reader/pdf.js +++ b/static/reader/pdf.js @@ -27,8 +27,6 @@ Ox.load({ } }, delay) selectAnnotation(data.id) - } else if (event == 'addAnnotation') { - createAnnotation() } else if (event == 'addAnnotations') { data.annotations.forEach(function(annotation) { annotations.push(annotation) @@ -46,25 +44,17 @@ window.addEventListener('keydown', function(event) { if (selected) { removeAnnotation(selected.dataset.id) } - } else if (event.key == 'n' || event.keyCode == 13) { - var selected = document.querySelector('.oml-annotation.selected') + } else if (event.key == 'n') { if (!window.getSelection().isCollapsed) { - createAnnotation() - } else if (selected) { - console.log('editNote?', selected.dataset.id) + var annot = getHighlight() + renderAnnotation(annot) + addAnnotation(annot) + window.getSelection().removeAllRanges(); } event.stopPropagation() 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() { if (!window.PDFViewerApplication || !window.PDFViewerApplication.eventBus) { @@ -99,18 +89,6 @@ 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) { var pageIndex = annotation.page - 1; var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex); @@ -161,7 +139,6 @@ function selectAnnotation(id) { g.style.backgroundColor = 'blue' }) } - function deselectAnnotation(id) { document.querySelectorAll('.oml-annotation.a' + id).forEach(function(g) { g.classList.remove('selected') @@ -169,20 +146,6 @@ function deselectAnnotation(id) { }) } -function deselectAllAnnotations() { - var ids = [] - document.querySelectorAll('.oml-annotation.selected').forEach(function(g) { - g.classList.remove('selected') - g.style.backgroundColor = 'yellow' - var id = $(g).parents('.oml-annotation').data('id') - console.log('deselect', g, id) - if (!Ox.contains(ids, id)) { - ids.push(id) - Ox.$parent.postMessage('deselectAnnotation', {id: id}) - } - }) -} - function removeAnnotation(id) { document.querySelectorAll('.oml-annotation.a' + id).forEach(function(a) { a.remove()