new TextHighlighter(element, options)
Creates TextHighlighter instance and binds to given DOM elements.
Parameters:
| Name | Type | Argument | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element |
HTMLElement | DOM element to which highlighted will be applied. |
|||||||||||||||||||||||||
options |
object |
<optional> |
Additional options. Properties
|
- Source:
Methods
-
<static> createWrapper(options) → {HTMLElement}
-
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 optionsobject The same object as in TextHighlighter constructor.
- Source:
Returns:
- Type
- HTMLElement
-
deserializeHighlights(json) → {Array}
-
Deserializes highlights.
Parameters:
Name Type Description jsonobject 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:
-
disable()
-
Disable highlighter.
- Since:
-
- 1.2.1
- Source:
-
doHighlight(keepRange)
-
Highlights current range.
Parameters:
Name Type Description keepRangeboolean Don't remove range after highlighting. Default: false.
- Source:
-
enable()
-
Enable highlighter.
- Since:
-
- 1.2.1
- Source:
-
find(text, caseSensitive)
-
Finds and highlights given text.
Parameters:
Name Type Argument Description textstring Text to search for
caseSensitiveboolean <optional>
If set to true, performs case sensitive search (default: true)
- Source:
-
flattenNestedHighlights(highlights)
-
Flattens highlights structure. Note: this method changes input highlights - their order and number after calling this method may change.
Parameters:
Name Type Description highlightsArray Highlights to flatten.
- Source:
-
getColor() → {string}
-
Returns highlighting color.
- Source:
Returns:
- Type
- string
-
getHighlights(params) → {Array}
-
Returns highlights from given container.
Parameters:
Name Type Description paramsobject Properties
Name Type Argument Description containerHTMLElement <optional>
Return highlights from this element.
Default: the element the highlighter is applied to.andSelfboolean <optional>
if set to true and container is a highlight itself, add container to returned results. Default: true.
groupedboolean <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. If set to "last" will return most last group added, and if set to "first", will return first group. Default: false.
- Source:
Returns:
Array of highlights.
- Type
- Array
-
highlightRange(range, wrapper) → {Array}
-
Highlights range. Wraps text of given range object in wrapper element.
Parameters:
Name Type Description rangeRange wrapperHTMLElement - Source:
Returns:
Array of created highlights.
- Type
- Array
-
isHighlight(el) → {boolean}
-
Returns true if element is a highlight. All highlights have 'data-highlighted' (DATA_ATTR) attribute.
Parameters:
Name Type Description elElement to check.
- Source:
Returns:
- Type
- boolean
-
mergeSiblingHighlights(highlights)
-
Merges sibling highlights and normalizes descendant text nodes. Note: this method changes input highlights Their order and number after calling this method may change.
Parameters:
Name Type Description highlights- Source:
-
normalizeHighlights(Highlights) → {Array}
-
Normalizes highlights. Ensures that highlighting is done with use of the smallest possible number of wrapping HTML elements. Flattens highlights structure and merges sibling highlights. Normalizes text nodes within highlights.
Parameters:
Name Type Description HighlightsArray Highlights to normalize.
- Source:
Returns:
Array of normalized highlights. Order and number of returned highlights may be different than input highlights.
- Type
- Array
-
removeHighlights(element)
-
Removes highlights from element. If element is a highlight itself, it is removed as well. If no element is given, all highlights are removed.
Parameters:
Name Type Description elementHTMLElement Element to remove highlights from.
- Source:
-
serializeHighlights(params) → {string}
-
Serializes all highlights in the element the highlighter is applied to.
Parameters:
Name Type Description paramsobject Params which are passed to
this.getHighlights.- Source:
Returns:
Stringified JSON with highlights definition
- Type
- string
-
setColor(color)
-
Sets highlighting color.
Parameters:
Name Type Description colorstring Valid CSS color.
- Source: