Methods
-
<static> createWrapper(options)
-
Creates wrapper for highlights.
TextHighlighter instance calls this method each time it needs to create highlights and pass options retrieved
in constructor.Parameters:
Name Type Description options
object the same object as in TextHighlighter constructor.
- Source:
Returns:
- Type
- HTMLElement
-
deserializeHighlights(json)
-
Deserializes 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
-
destroy()
-
Permanently disables highlighting.
Unbinds events and remove context element class.- Source:
-
find(text [, caseSensitive])
-
Finds and highlights given text.
Parameters:
Name Type Argument Description text
string text to search for
caseSensitive
boolean <optional>
if set to true, performs case sensitive search (default: true)
- 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.This is only supported by independencia (v2-2019) and onwards.
For older versions, this will simply do nothing.Parameters:
Name Type Description id
string The id of the highlight present in the class names of all elements
in the DOM that represent the highlight.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:
-
getColor()
-
Returns highlighting color.
- Source:
Returns:
- Type
- string
-
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
-
highlightHandler()
-
Listener to events that can trigger the creation of a highlight.
By default this is triggered on "mouseup" and "touchend" events.
If you disable the default events by setting options.useDefaultEvents
you will need to register this handler with your own events and make sure you
remove the listener when you destroy the instance of the TextHighlighter as well.- Source:
-
highlightRange(range, wrapper)
-
Highlights range.
Wraps text of given range object in wrapper element.Parameters:
Name Type Description range
Range wrapper
HTMLElement - Source:
Returns:
- array of created highlights.
- Type
- Array
-
isHighlight(el)
-
Returns true if element is a highlight.
All highlights have 'data-highlighted' attribute.Parameters:
Name Type Description el
element to check.
- Source:
Returns:
- Type
- boolean
-
normalizeHighlights(highlights)
-
Normalizes highlights. Ensure at least text nodes are normalized, carries out some flattening and nesting
where necessary.Parameters:
Name Type Description highlights
Array highlights to normalize.
- Source:
Returns:
- array of normalized highlights. Order and number of returned highlights may be different than
input highlights.
- Type
- Array
-
registerDefaultEvents()
-
Registers the default event listeners that trigger the proecss
of creating a highlight.- Source:
-
removeHighlights(element, id)
-
Removes highlights from element. If element is a highlight itself, it is removed as well.
If no element is given, all highlights all removed.Parameters:
Name Type Description element
HTMLElement element to remove highlights from.
if empty, the root element of the highlighter will be used.id
string The unique id of a highlight represented by a collection of elements.
- Source:
-
serializeHighlights(id)
-
Serializes all highlights in the element the highlighter is applied to.
the id is not used in the initial version of the highlighter.Parameters:
Name Type Description id
string The unique identifier grouping a set of highlight elements together.
- Source:
Returns:
- stringified JSON with highlights definition
- Type
- string
-
setColor(color)
-
Sets highlighting color.
Parameters:
Name Type Description color
string valid CSS color.
- Source:
Type Definitions
-
HighlightDescriptor
-
Deselects a highlight, bringing any nested highlights in the list of descriptors
forward.This is only supported by independencia (v2-2019) and onwards.
For older versions, this will simply do nothing.Type:
- object
- Source:
Properties:
Name Type Description id
string serialisedDescriptor
string