Highlighter Controller is a Stimulus controller for highlighting words.
These are standard HTML attributes (with no prefix) used by Table Filter.
| Attribute | Element(s) | Default | Value(s) | Description |
|---|---|---|---|---|
| aria-busy |
(root) |
false |
true false |
Highlighter will set this to true any time it is applying highlighting. You can use the value in your CSS to indicate that work is in progress. |
All of these attributes are prefixed with "data-" in the attribute name.
| Attribute | Element(s) | Default | Value(s) | Description |
|---|---|---|---|---|
| controller |
(any) |
highlighter |
This attribute provides the highlighter functionality. |
All of these attributes are prefixed with "data-highlighter-" in the attribute name.
| Attribute | Element(s) | Default | Value(s) | Description |
|---|---|---|---|---|
| class |
(controller) |
highlight |
The class to add to the highlighted words. |
|
| color |
(controller) |
yellow |
The color to use for the highlighted words. Only used if no style is applied to the highlight class. |
|
| words |
(controller) |
The words to highlight. Space-delimited. |
These are custom events that the controller will fire when it takes certain actions.
All of these events are prefixed by "highlighter:".
| Event | Parameters | Description |
|---|---|---|
| initialized | Called any time that the controller is initialized. | |
| connected | Called any time that the controller is connected. | |
| disconnected | Called any time that the controller is disconnected. | |
| highlighted |
target: (the element in which words are highlighted). words: (the words that were highlighted). |
Called any time that the controller highlights words. |
While it is recommended to use the controller via the attributes listed above, the following methods can be called directly if needed.
| Method | Returns | Arguments | Event(s) | Description |
|---|---|---|---|---|
| getHighlightClass | (string) |
Get the class that will be applied to highlighted words. |
||
| getHighlightColor | (string) |
Get the color that will be applied to highlighted words if no styles are set for the class. |
||
| addWord |
Add a word to the list of words to be highlighted. |
|||
| getWordsArray | (array) |
Get the words that will be highlighted. |
||
| getWordsString | (string) |
Get the words that will be highlighted. |
||
| highlightWords |
Highlights the words in the data-highlighter-words attribute. |
|||
| setHighlightClass | className (string) |
Set the class that will be applied to highlighted words. |
||
| setHighlightColor | color (string) |
Set the color that will be applied to highlighted words if no style is applied to the highlight class externally. |
||
| setWordsArray | words (array) |
Set the words that will be highlighted. |
||
| setWordsString | words (string) |
Set the words that will be highlighted. |