Merge branch 'master' of code.0x2620.org:0x2620/openmedialibrary
This commit is contained in:
commit
b5d0a9f136
3 changed files with 61 additions and 39 deletions
|
|
@ -3,6 +3,7 @@
|
|||
oml.ui.viewer = function() {
|
||||
|
||||
var ui = oml.user.ui,
|
||||
annotations = [],
|
||||
|
||||
frame = Ox.Element(),
|
||||
that = Ox.Element()
|
||||
|
|
@ -38,6 +39,24 @@ oml.ui.viewer = function() {
|
|||
.appendTo(that),
|
||||
$iframe, item;
|
||||
|
||||
function loadAnnotations(callback) {
|
||||
annotations = JSON.parse(localStorage[item + '.annotations'] || '[]')
|
||||
callback && callback(annotations)
|
||||
}
|
||||
function saveAnnotations(data) {
|
||||
if (data) {
|
||||
data.created = data.created || (new Date).toISOString();
|
||||
annotations.push(data);
|
||||
}
|
||||
localStorage[item + '.annotations'] = JSON.stringify(annotations)
|
||||
}
|
||||
function removeAnnotation(id) {
|
||||
annotations = annotations.filter(function(annotation) {
|
||||
return annotation.id != id
|
||||
})
|
||||
saveAnnotations()
|
||||
}
|
||||
|
||||
that.updateElement = function() {
|
||||
item = ui.item;
|
||||
if (item && item.length) {
|
||||
|
|
@ -55,18 +74,36 @@ oml.ui.viewer = function() {
|
|||
console.log('got', event, data)
|
||||
if (event == 'addAnnotation') {
|
||||
console.log('adding', data.id)
|
||||
saveAnnotations(data);
|
||||
var $annotation = oml.ui.annotation(data, $iframe)
|
||||
oml.$ui.annotationFolder.append($annotation);
|
||||
$annotation.annotate();
|
||||
} else if (event == 'removeAnnotation') {
|
||||
console.log('do it ...', data)
|
||||
oml.$ui.annotationFolder.find('#a-' + data.id).remove()
|
||||
removeAnnotation(data.id)
|
||||
} else if (event == 'selectAnnotation') {
|
||||
console.log('select', data)
|
||||
} else if (event == 'deselectAnnotation') {
|
||||
console.log('deselect', data)
|
||||
} else {
|
||||
that.triggerEvent(event, data);
|
||||
}
|
||||
|
||||
}).bindEvent({
|
||||
init: function() {
|
||||
loadAnnotations(function(annotations) {
|
||||
annotations.forEach(function(data) {
|
||||
var $annotation = oml.ui.annotation(data, $iframe)
|
||||
oml.$ui.annotationFolder.append($annotation);
|
||||
})
|
||||
// fixme: trigger loaded event from reader instead?
|
||||
setTimeout(function() {
|
||||
that.postMessage('addAnnotations', {
|
||||
annotations: annotations
|
||||
})
|
||||
}, 500)
|
||||
})
|
||||
}
|
||||
that.triggerEvent(event, data);
|
||||
}).appendTo(frame);
|
||||
$iframe.attr({
|
||||
src: '/' + item + '/reader/'
|
||||
|
|
@ -77,7 +114,7 @@ oml.ui.viewer = function() {
|
|||
return that;
|
||||
};
|
||||
that.postMessage = function(event, data) {
|
||||
$iframe && $iframe.postMesage(event, data)
|
||||
$iframe && $iframe.postMessage(event, data)
|
||||
};
|
||||
|
||||
return that.updateElement();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue