The highlight text component for Riot.js
Installation
npm ins --save-dev riot-hi-text
Examples
Basic
Import script, the standalone script files are in the dist
.
Webpack or Browserify:
Create tags
Hello highlight text!!!!
var hiTextTags = riothiTextTags
yield:
every h
will warp with <span class="highlight">
Hello highlight text!!!!
Dynamic
{text} this.tags['hi-text'].text = 'hello hi text!!'
Options
opts['class-name']
Custom class name, default is highlight
opts['case-sensitive']
Match word with case sensitive. default is false
equal to
API
setHighlight(word, [case_sensitive = false])
Set highlight with word
clean()
Clean all highlight.
hasMatched
true
or false
, change everytime after invoking setHighlight()
Asynchronous
{text} var tag = this $.ajax({ url: '/api/case' }) .done(function(data){ tag.tags['h1-text'].text = data tag.tags['h1-text'].update() tag.tags['h1-text'].setHeightlight('hi') })
With chain
The API all return tag instance itself, so you can chain the method
tag