openmedialibrary/static/js/annotation.js

62 lines
2 KiB
JavaScript
Raw Normal View History

2019-01-23 15:14:59 +00:00
'use strict';
2019-01-24 12:49:21 +00:00
oml.ui.annotation = function(annotation, $iframe) {
2019-01-24 09:20:25 +00:00
var $arrayEditable = Ox.ArrayEditable({
editing: true,
2019-01-24 12:49:21 +00:00
items: (annotation.comments || []).map(function(comment) {
comment.editable = true
return comment
}),
2019-01-24 09:20:25 +00:00
type: 'textarea'
}).css({
minHeight: '16px'
2019-01-24 12:49:21 +00:00
}).bindEvent({
submit: function(data) {
var comment = Ox.getObjectById(annotation.comments, data.id)
if (comment) {
comment.value = data.value
comment.modified = (new Date).toISOString()
} else {
annotation.comments.push({
created: data.created || (new Date).toISOString(),
modified: (new Date).toISOString(),
id: data.id,
value: data.value
})
}
that.triggerEvent('change')
}
2019-01-24 09:20:25 +00:00
});
2019-01-23 15:14:59 +00:00
var that = Ox.Element().attr({
2019-01-24 12:49:21 +00:00
id: 'a-' + annotation.id
2019-01-24 05:39:09 +00:00
}).addClass(
'OxSelectable'
).css({
borderBottom: '1px solid rgb(208, 208, 208)',
2019-01-24 07:22:40 +00:00
}).append(
Ox.Element().addClass('OxSelectable').css({
backgroundColor: 'white',
color: 'black',
fontFamily: 'Georgia, Palatino, DejaVu Serif, Book Antiqua, Palatino Linotype, Times New Roman, serif',
fontSize: '14px',
lineHeight: '21px',
padding: '8px'
2019-01-24 12:49:21 +00:00
}).html(Ox.encodeHTMLEntities(annotation.text).replace(/\n/g, '<br/>')).on({
2019-01-24 07:22:40 +00:00
click: function(event) {
$iframe.postMessage('selectAnnotation', {
2019-01-24 12:49:21 +00:00
id: annotation.id
2019-01-24 07:22:40 +00:00
})
}
})
2019-01-24 09:20:25 +00:00
).append($arrayEditable);
that.annotate = function() {
var item = {
id: 'note', value: '', editable: true
}
$arrayEditable.addItem(0, item)
.options({selected: item.id})
.editItem();
}
2019-01-23 15:14:59 +00:00
return that;
};