diff --git a/static/js/annotation.js b/static/js/annotation.js index b6e9368..01b8582 100644 --- a/static/js/annotation.js +++ b/static/js/annotation.js @@ -82,6 +82,11 @@ oml.ui.annotation = function(annotation, $iframe) { addNote() } } + that.delete = function() { + that.triggerEvent('delete', { + id: annotation.id + }) + } that.deselect = function() { that.removeClass('selected') that.loseFocus() @@ -94,7 +99,8 @@ oml.ui.annotation = function(annotation, $iframe) { selected && selected.classList.remove('selected') that.addClass('selected') that.gainFocus() - that[0].scrollIntoViewIfNeeded() + oml.$ui.annotationPanel.updateSelection(false) + that[0].scrollIntoViewIfNeeded && that[0].scrollIntoViewIfNeeded() } return that; }; diff --git a/static/js/annotationPanel.js b/static/js/annotationPanel.js index 0860c0d..81196e6 100644 --- a/static/js/annotationPanel.js +++ b/static/js/annotationPanel.js @@ -6,7 +6,7 @@ oml.ui.annotationPanel = function() { var $bar = Ox.Bar({size: 16}); - var $button = Ox.Button({ + var $addQuote = Ox.Button({ disabled: true, style: 'symbol', title: 'add', @@ -18,6 +18,19 @@ oml.ui.annotationPanel = function() { } }).appendTo($bar); + var $deleteQuote = Ox.Button({ + disabled: true, + style: 'symbol', + title: 'remove', + tooltip: Ox._('Delete Quote'), + type: 'image' + }).bindEvent({ + click: function() { + var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected') + $annotation.length && $annotation.delete() + } + }).appendTo($bar); + var $menuButton = Ox.MenuButton({ items: [ {id: 'addAnnotation', title: 'Add Annotation', disabled: true}, @@ -86,9 +99,13 @@ oml.ui.annotationPanel = function() { }); that.updateSelection = function(selection) { - $button.options({ + $addQuote.options({ disabled: !selection }) + var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected') + $deleteQuote.options({ + disabled: !$annotation.length + }) } return that; diff --git a/static/js/viewer.js b/static/js/viewer.js index 1eb49ca..6e73a22 100644 --- a/static/js/viewer.js +++ b/static/js/viewer.js @@ -98,6 +98,7 @@ oml.ui.viewer = function() { var $annotation = oml.ui.annotation(data, $iframe).bindEvent(annotationEvents) oml.$ui.annotationFolder.append($annotation); $annotation.annotate(); + oml.$ui.annotationPanel.updateSelection(false) } else if (event == 'removeAnnotation') { oml.$ui.annotationFolder.find('#a-' + data.id).remove() removeAnnotation(data.id) @@ -109,6 +110,7 @@ oml.ui.viewer = function() { var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected') $annotation.length && $annotation.deselect() } + oml.$ui.annotationPanel.updateSelection(false) } else if (event == 'selectText') { oml.$ui.annotationPanel.updateSelection(data) } else { diff --git a/static/reader/epub.js b/static/reader/epub.js index 9aca10f..ae870b9 100644 --- a/static/reader/epub.js +++ b/static/reader/epub.js @@ -172,6 +172,7 @@ document.onreadystatechange = function () { } }).on('mouseup', function(event) { if (currentSelection) { + deselectAllAnnotations() var selection = window.getSelection() if (selection.isCollapsed) { currentSelection = null