In my application, I need to store some extra metadata about the selected ranges. (Specifically: I have data-text-id attributes for each line of text, so I want to store the start and end ID of the selected text.) I currently do something like this:
beforeAnnotationCreated: function(annotation) {
annotation['textids'] = annotation.ranges.map(function(range) {
var domRange = Range.sniff(range).normalize(root);
if (domRange.limit(options.element) !== null) {
return {
start: getTextId(domRange.start),
end: getTextId(domRange.end)
}
} else {
// fallback path elided
return null;
}
}).filter(function(o) { return !!o; });
}
It's a bit sad that I have to reconstruct information that Annotator has but does not expose. Perhaps beforeAnnotationCreated and friends could receive a second dictionary of information like this, derived from the data which will actually be stored? I'm not quite sure what it would look like.
In my application, I need to store some extra metadata about the selected ranges. (Specifically: I have
data-text-idattributes for each line of text, so I want to store the start and end ID of the selected text.) I currently do something like this:It's a bit sad that I have to reconstruct information that Annotator has but does not expose. Perhaps
beforeAnnotationCreatedand friends could receive a second dictionary of information like this, derived from the data which will actually be stored? I'm not quite sure what it would look like.