Skip to content
This repository has been archived by the owner on May 30, 2018. It is now read-only.

Commit

Permalink
bump to v0.6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
marexandre committed Jun 26, 2015
1 parent ca83ca7 commit ea16606
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ This is the basic usage in javascript:
$('#someElement').textareaHighlighter({
matches: [
{
'priority': 1, // if there is overlap with other matches it will highlight a match that has a higher priority
'priority': 2, // if there is overlap with other matches it will highlight a match that has a higher priority
'match': ['this is a test', 'text to match'], // will check for this matches
'matchClass': 'match' // this class will be added to the matching string
}, {
'priority': 1,
'match': /\{\/?\d+\}/g,
'matchClass': 'tags'
}, {
'priority': 0,
'match': ['some', 'more', 'here'],
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-textarea-highlighter",
"version": "0.6.5",
"version": "0.6.6",
"main": "jquery.textarea-highlighter.js",
"ignore": [
"screenshot.png",
Expand Down
16 changes: 13 additions & 3 deletions jquery.textarea-highlighter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* jquery.textarea-highlighter.js - jQuery plugin for highlighting text in textarea.
* @version v0.6.5
* @version v0.6.6
* @link https://github.com/marexandre/jquery.textarea-highlighter.js
* @author alexandre.kirillov@gmail.com
* @license MIT license. http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -409,6 +409,9 @@ var marexandre;

// Remove duplicates from 'match'
for (var i = 0, imax = settings.matches.length; i < imax; i++) {
if (settings.matches[i].match instanceof RegExp) {
continue;
}
settings.matches[i].match = helper.getUniqueArray(settings.matches[i].match);
}

Expand Down Expand Up @@ -531,15 +534,22 @@ var marexandre;
var list = _this.settings.matches;
var indeciesList = [];
var item, trieIndecies;
var matches;

for (var i = 0, imax = list.length; i < imax; i++) {
item = list[i];

if (!item._trie) {
item._trie = new marexandre.Trie();
if (item.match instanceof RegExp) {
matches = helper.getUniqueArray(text.match(item.match));
} else {
matches = item.match;
}

// HTML escape matching words
for (var j = 0, jmax = item.match.length; j < jmax; j++) {
item._trie.add( helper.escapeHTML(item.match[j]) );
for (var j = 0, jmax = matches.length; j < jmax; j++) {
item._trie.add( helper.escapeHTML(matches[j]) );
}
}

Expand Down
Loading

0 comments on commit ea16606

Please sign in to comment.