rename selection event to selectText, replace deselectAnnotation with selectAnnotation({id: null})

This commit is contained in:
j 2019-02-01 14:19:16 +05:30
parent 5186079059
commit 2c5c56c036
3 changed files with 15 additions and 16 deletions

View file

@ -71,8 +71,6 @@ oml.ui.viewer = function() {
var annotationEvents = { var annotationEvents = {
change: function() { change: function() {
console.log('change...')
console.log(annotations)
saveAnnotations() saveAnnotations()
}, },
'delete': function(data) { 'delete': function(data) {
@ -96,7 +94,6 @@ oml.ui.viewer = function() {
border: 0 border: 0
}).onMessage(function(data, event) { }).onMessage(function(data, event) {
if (event == 'addAnnotation') { if (event == 'addAnnotation') {
console.log('adding', data.id)
saveAnnotations(data); saveAnnotations(data);
var $annotation = oml.ui.annotation(data, $iframe).bindEvent(annotationEvents) var $annotation = oml.ui.annotation(data, $iframe).bindEvent(annotationEvents)
oml.$ui.annotationFolder.append($annotation); oml.$ui.annotationFolder.append($annotation);
@ -105,12 +102,14 @@ oml.ui.viewer = function() {
oml.$ui.annotationFolder.find('#a-' + data.id).remove() oml.$ui.annotationFolder.find('#a-' + data.id).remove()
removeAnnotation(data.id) removeAnnotation(data.id)
} else if (event == 'selectAnnotation') { } else if (event == 'selectAnnotation') {
var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id) if (data.id) {
$annotation && $annotation.select() var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)
} else if (event == 'deselectAnnotation') { $annotation.length && $annotation.select()
var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)[0] } else {
$annotation && $annotation.deselect() var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
} else if (event == 'selection') { $annotation.length && $annotation.deselect()
}
} else if (event == 'selectText') {
oml.$ui.annotationPanel.updateSelection(data) oml.$ui.annotationPanel.updateSelection(data)
} else { } else {
console.log('got', event, data) console.log('got', event, data)

View file

@ -81,7 +81,7 @@ function deselectAllAnnotations() {
g.classList.remove('selected') g.classList.remove('selected')
if (!Ox.contains(ids, id)) { if (!Ox.contains(ids, id)) {
ids.push(id) ids.push(id)
Ox.$parent.postMessage('deselectAnnotation', {id: id}) Ox.$parent.postMessage('selectAnnotation', {id: null})
} }
}) })
} }
@ -179,7 +179,7 @@ document.onreadystatechange = function () {
currentSelection = null currentSelection = null
} }
if (!currentSelection) { if (!currentSelection) {
Ox.$parent.postMessage('selection', false) Ox.$parent.postMessage('selectText', false)
} }
} }
}) })
@ -194,7 +194,7 @@ document.onreadystatechange = function () {
text: text, text: text,
contents: contents contents: contents
} }
Ox.$parent.postMessage('selection', text ? true : false) Ox.$parent.postMessage('selectText', text ? true : false)
}) })
}); });
} }

View file

@ -60,9 +60,9 @@ window.addEventListener('keydown', function(event) {
window.addEventListener('mouseup', function(event) { window.addEventListener('mouseup', function(event) {
var selection = window.getSelection() var selection = window.getSelection()
if (selection.isCollapsed) { if (selection.isCollapsed) {
Ox.$parent.postMessage('selection', false) Ox.$parent.postMessage('selectText', false)
} else { } else {
Ox.$parent.postMessage('selection', true) Ox.$parent.postMessage('selectText', true)
} }
}) })
@ -136,7 +136,7 @@ function renderAnnotation(annotation) {
el.addEventListener('click', function() { el.addEventListener('click', function() {
if (el.classList.contains('selected')) { if (el.classList.contains('selected')) {
deselectAnnotation(annotation.id) deselectAnnotation(annotation.id)
Ox.$parent.postMessage('deselectAnnotation', {id: annotation.id}) Ox.$parent.postMessage('selectAnnotation', {id: null})
} else { } else {
selectAnnotation(annotation.id) selectAnnotation(annotation.id)
Ox.$parent.postMessage('selectAnnotation', {id: annotation.id}) Ox.$parent.postMessage('selectAnnotation', {id: annotation.id})
@ -178,7 +178,7 @@ function deselectAllAnnotations() {
console.log('deselect', g, id) console.log('deselect', g, id)
if (!Ox.contains(ids, id)) { if (!Ox.contains(ids, id)) {
ids.push(id) ids.push(id)
Ox.$parent.postMessage('deselectAnnotation', {id: id}) Ox.$parent.postMessage('selectAnnotation', {id: null})
} }
}) })
} }