texthighlight.add - Events - Annotations API

Annotations API Events

texthighlight:add

Triggered whenever a text highlight is added.

Examples

annotationsApp.on('texthighlight:add', function (textHighlightInfo) {
    var textHighlightModule = annotationsApp.module('texthighlight');
    var id = textHighlightInfo.id;
    var startElement = textHighlightModule.utils.deserializePath(
        textHighlightInfo.startContainerPath,
        textHighlightInfo.startOffset,
    );
    var endElement = textHighlightModule.utils.deserializePath(
        textHighlightInfo.endContainerPath,
        textHighlightInfo.endOffset,
    );

    console.log('The text selection with id ' + id + ' ranges between:', startElement, endElement);
});

Callback arguments

  • id string

    The unique id of the text highlight.

  • startContainerPath string

    A string representing the location of the DOM node that contains the start of the selection.

  • endContainerPath string

    A string representing the location of the DOM node that contains the end of the selection.

  • startOffset number

    The offset, in characters, of the start of the selection within the start container.

  • endOffset number

    The offset, in characters, of the end of the selection within the end container.

Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.