Class: IndependenciaHighlighter

IndependenciaHighlighter


new IndependenciaHighlighter(element [, options])

Creates an IndependenciaHighlighter instance for functionality that focuses for highlight independence.

Parameters:
Name Type Argument Description
element HTMLElement

DOM element to which highlighted will be applied.

options object <optional>

additional options.

Properties
Name Type Description
color string

highlight color.

excludeNodes string

Node types to exclude when calculating offsets and determining where to inject highlights.

highlightedClass string

class added to highlight, 'highlighted' by default.

contextClass string

class added to element to which highlighter is applied,
'highlighter-context' by default.

onRemoveHighlight function

function called before highlight is removed. Highlight is
passed as param. Function should return true if highlight should be removed, or false - to prevent removal.

onBeforeHighlight function

function called before highlight is created. Range object is
passed as param. Function should return true to continue processing, or false - to prevent highlighting.

preprocessDescriptors PreprocessDescriptors

function called after the user has carried out the action
to trigger creation of highlights after making a text selection. This should be used to customise the highlight span wrapper
with custom data attributes or styles required before the highlight is loaded into the DOM.
This callback must return an array of highlight descriptors.

onAfterHighlight OnAfterHighlightCallbackV2

function called after highlight is created. Array of created
wrappers is passed as param. This is called after the highlight has been created in the DOM.

Source:

Methods


deserializeHighlights(json)

Deserializes the independent form of highlights.

Parameters:
Name Type Description
json object

JSON object with highlights definition.

Source:
Throws:

exception when can't parse JSON or JSON has invalid structure.

Returns:
  • array of deserialized highlights.
Type
Array

doHighlight(keepRange)

Highlights current range.

Parameters:
Name Type Description
keepRange boolean

Don't remove range after highlighting. Default: false.

Source:

focusUsingId(id, descriptors)

Focuses a highlight, bringing it forward in the case it is sitting behind another
overlapping highlight, or a highlight it is nested inside.

Parameters:
Name Type Description
id object

The id of the highlight present in the class names of all elements
in the DOM that represent the highlight.

In order to utilise this functionality unique ids for highlights should be added to the class list in the highlight
wrapper within the descriptors.
You can do this in the onAfterHighlight callback when a highlight is first created.

In the future it might be worth adding more flexiblity to allow for user-defined ways of storing ids to identify
elements in the DOM. (e.g. choosing between class name or data attributes)

descriptors string

Optional serialised descriptors, useful in the case a highlight has no representation in the DOM
where empty highlight wrapper nodes are removed to use less dom elements.

Source:

getHighlights(params)

Returns highlights from given container.

Parameters:
Name Type Description
params
Properties
Name Type Argument Description
container HTMLElement <optional>

return highlights from this element. Default: the element the
highlighter is applied to.

andSelf boolean <optional>

if set to true and container is a highlight itself, add container to
returned results. Default: true.

grouped boolean <optional>

if set to true, highlights are grouped in logical groups of highlights added
in the same moment. Each group is an object which has got array of highlights, 'toString' method and 'timestamp'
property. Default: false.

Source:
Returns:
  • array of highlights.
Type
Array

isHighlight(el, dataAttr)

Returns true if element is a highlight.

Parameters:
Name Type Description
el

element to check.

dataAttr

data attribute to determine if the element is a highlight

Source:
Returns:
Type
boolean

normalizeHighlights()

Normalizes highlights and the dom. Ensures text nodes within any given element node are merged together, elements with the
same ID next to each other are merged together and highlights with the same ID next to each other are merged together.

Source:

removeHighlights(element, id)

Removes one highlight if an ID is provided, removes all highlights in the provided
element otherwise.

Parameters:
Name Type Description
element HTMLElement

element to remove highlights from

id string

ID of highlight to remove
Removes highlights from element using highlight ID.
If no id is given, all highlights are removed.

Source:

serializeHighlights(id)

Serializes the highlight belonging to the ID.

Parameters:
Name Type Description
id

ID of the highlight to serialise

Source:
Returns:
  • stringified JSON with highlights definition
Type
string

Type Definitions


HighlightDescriptor

Deselects a highlight, bringing any nested highlights in the list of descriptors
forward.

In order to utilise this functionality unique ids for highlights should be added to the class list in the highlight
wrapper within the descriptors.
You can do this in the onAfterHighlight callback when a highlight is first created.

In the future it might be worth adding more flexiblity to allow for user-defined ways of storing ids to identify
elements in the DOM. (e.g. choosing between class name or data attributes)

Type:
  • object
Properties:
Name Type Description
id string
serialisedDescriptor string
Source: