From 85cdde0149ffefde518e536994f0f0b6d2af9eab Mon Sep 17 00:00:00 2001 From: Houssem Date: Tue, 11 Jul 2017 12:16:47 +0200 Subject: [PATCH] skip highlight the possibility to skip highlighting some part of the suggestion, it is specially usefull when using material icons, where the icons would be highlighted and the icon would be gone in the current version, this change is to adress this issue, --- src/typeahead/dataset.js | 1 + src/typeahead/highlight.js | 21 ++++++++++++--------- src/typeahead/www.js | 3 ++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/typeahead/dataset.js b/src/typeahead/dataset.js index fce09c30..477411bb 100644 --- a/src/typeahead/dataset.js +++ b/src/typeahead/dataset.js @@ -198,6 +198,7 @@ var Dataset = (function() { this.highlight && highlight({ className: this.classes.highlight, + skipHighlight: this.classes.skipHighlight, node: fragment, pattern: query }); diff --git a/src/typeahead/highlight.js b/src/typeahead/highlight.js index 1e338214..ae8455bc 100644 --- a/src/typeahead/highlight.js +++ b/src/typeahead/highlight.js @@ -6,17 +6,18 @@ // inspired by https://github.com/jharding/bearhug -var highlight = (function(doc) { +var highlight = (function (doc) { 'use strict'; var defaults = { - node: null, - pattern: null, - tagName: 'strong', - className: null, - wordsOnly: false, - caseSensitive: false - }; + node: null, + pattern: null, + tagName: 'strong', + className: null, + skipHighlight: null, + wordsOnly: false, + caseSensitive: false + }; return function hightlight(o) { var regex; @@ -57,7 +58,9 @@ var highlight = (function(doc) { for (var i = 0; i < el.childNodes.length; i++) { childNode = el.childNodes[i]; - if (childNode.nodeType === TEXT_NODE_TYPE) { + if ($(childNode).hasClass(o.skipHighlight)) { + continue; + } else if (childNode.nodeType === TEXT_NODE_TYPE) { i += hightlightTextNode(childNode) ? 1 : 0; } diff --git a/src/typeahead/www.js b/src/typeahead/www.js index 065af1f8..9db5ec51 100644 --- a/src/typeahead/www.js +++ b/src/typeahead/www.js @@ -18,7 +18,8 @@ var WWW = (function() { empty: 'tt-empty', open: 'tt-open', cursor: 'tt-cursor', - highlight: 'tt-highlight' + highlight: 'tt-highlight', + skipHighlight: 'tt-skip-highlight' }; return build;