new IndependenciaHighlighter(element, optionsopt)
- Source:
Creates an IndependenciaHighlighter instance for functionality that focuses for highlight independence.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element |
HTMLElement | DOM element to which highlighted will be applied. |
|||||||||||||||||||||||||||||||||||||||||||
options |
object |
<optional> |
additional options. Properties
|
Methods
deserializeHighlights(json) → {Array}
- Source:
Deserializes the independent form of highlights.
Parameters:
Name | Type | Description |
---|---|---|
json |
object | JSON object with highlights definition. |
Throws:
exception when can't parse JSON or JSON has invalid structure.
Returns:
- array of deserialized highlights.
- Type
- Array
doHighlight(keepRange)
- Source:
Highlights current range.
Parameters:
Name | Type | Description |
---|---|---|
keepRange |
boolean | Don't remove range after highlighting. Default: false. |
focusUsingId(id, descriptors)
- Source:
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 order to utilise this functionality unique ids for highlights should be added to the class list in the highlight In the future it might be worth adding more flexiblity to allow for user-defined ways of storing ids to identify |
descriptors |
string | Optional serialised descriptors, useful in the case a highlight has no representation in the DOM |
getHighlights(params) → {Array}
- Source:
Returns highlights from given container.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Properties
|
Returns:
- array of highlights.
- Type
- Array
isHighlight(el, dataAttr) → {boolean}
- Source:
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 |
Returns:
- Type
- boolean
normalizeHighlights()
- Source:
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.
removeHighlights(element, id)
- Source:
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 |
serializeHighlights(id) → {string}
- Source:
Serializes the highlight belonging to the ID.
Parameters:
Name | Type | Description |
---|---|---|
id |
ID of the highlight to serialise |
Returns:
- stringified JSON with highlights definition
- Type
- string
Type Definitions
HighlightDescriptor
- Source:
Properties:
Name | Type | Description |
---|---|---|
id |
string | |
serialisedDescriptor |
string |
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