Skip to content

Commit

Permalink
Fix highlight not working after first highlight insert #1098
Browse files Browse the repository at this point in the history
  • Loading branch information
skimi authored and joallard committed Jul 20, 2016
1 parent 457e420 commit 6ded59d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/contrib/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ var highlight = function($element, pattern) {
return $element.each(function() {
highlight(this);
});
};
};

/**
* removeHighlight fn copied from highlight v5 and
* edited to remove with() and pass js strict mode
*/
jQuery.fn.removeHighlight = function() {
return this.find("span.highlight").each(function() {
this.parentNode.firstChild.nodeName;
var parent = this.parentNode;
parent.replaceChild(this.firstChild, this);
parent.normalize();
}).end();
};
1 change: 1 addition & 0 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ $.extend(Selectize.prototype, {

// highlight matching terms inline
if (self.settings.highlight && results.query.length && results.tokens.length) {
$dropdown_content.removeHighlight();
for (i = 0, n = results.tokens.length; i < n; i++) {
highlight($dropdown_content, results.tokens[i].regex);
}
Expand Down

2 comments on commit 6ded59d

@naskomit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jQuery.fn.removeHighlight must be $.fn.removeHighlight. The first one only works if a global jQuery is present.

@joallard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naskomit See #1143 and the master branch

Please sign in to comment.