Skip to content

Make the DOM elements of the selection easily available to extensions #549

@wjt

Description

@wjt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions