bind delete in annotation folder

This commit is contained in:
j 2019-01-31 11:52:19 +05:30
parent 0d76284684
commit 943d117c89
4 changed files with 25 additions and 7 deletions

View file

@ -49,6 +49,12 @@ oml.ui.annotation = function(annotation, $iframe) {
'OxSelectable OMLAnnotation' 'OxSelectable OMLAnnotation'
).css({ ).css({
borderBottom: '1px solid rgb(208, 208, 208)', borderBottom: '1px solid rgb(208, 208, 208)',
}).bindEvent({
key_delete: function() {
that.triggerEvent('delete', {
id: annotation.id
})
}
}).append($quote).append($note); }).append($quote).append($note);
that.annotate = function() { that.annotate = function() {
@ -63,6 +69,7 @@ oml.ui.annotation = function(annotation, $iframe) {
let selected = document.querySelector('.OMLAnnotation.selected') let selected = document.querySelector('.OMLAnnotation.selected')
selected && selected.classList.remove('selected') selected && selected.classList.remove('selected')
that.addClass('selected') that.addClass('selected')
that.gainFocus()
} }
return that; return that;
}; };

View file

@ -63,6 +63,10 @@ oml.ui.viewer = function() {
console.log('change...') console.log('change...')
console.log(annotations) console.log(annotations)
saveAnnotations() saveAnnotations()
},
'delete': function(data) {
oml.$ui.annotationFolder.find('#a-' + data.id).remove()
that.postMessage('removeAnnotation', data)
} }
} }

View file

@ -23,6 +23,8 @@ Ox.load({
annotations.push(annotation) annotations.push(annotation)
renderAnnotation(annotation) renderAnnotation(annotation)
}) })
} else if (event == 'removeAnnotation') {
removeAnnotation(data.id)
} }
}) })
}) })
@ -47,12 +49,15 @@ function deselectAnnotation(id) {
}) })
} }
function removeAnnotation(a) { function removeAnnotation(id) {
annotations = annotations.filter(function(annotation) { var a = annotations.filter(function(a) { return a.id == id })[0]
return annotation.cfiRange != a.dataset.epubcfi if (a) {
}) annotations = annotations.filter(function(annotation) {
reader.rendition.annotations.remove(a.dataset.epubcfi) return annotation.id != id
Ox.$parent.postMessage('removeAnnotation', {id: a.dataset.id}) })
reader.rendition.annotations.remove(a.cfiRange)
}
Ox.$parent.postMessage('removeAnnotation', {id: id})
} }
function renderAnnotation(annotation) { function renderAnnotation(annotation) {
@ -98,7 +103,7 @@ document.onreadystatechange = function () {
reader.rendition.on('keydown', function(event) { reader.rendition.on('keydown', function(event) {
if (event.key == 'Delete') { if (event.key == 'Delete') {
document.querySelectorAll('.epubjs-hl.selected').forEach(function(a) { document.querySelectorAll('.epubjs-hl.selected').forEach(function(a) {
removeAnnotation(a) removeAnnotation(a.dataset.id)
}) })
} }
if (event.key == 'n') { if (event.key == 'n') {

View file

@ -32,6 +32,8 @@ Ox.load({
annotations.push(annotation) annotations.push(annotation)
renderAnnotation(annotation) renderAnnotation(annotation)
}) })
} else if (event == 'removeAnnotation') {
removeAnnotation(data.id)
} }
}) })
}) })