From 0f4d81b9a5d895229c314d9d3146865c3a6f3605 Mon Sep 17 00:00:00 2001 From: Max Guglielmi Date: Sat, 13 Dec 2014 20:04:25 +1100 Subject: [PATCH] Added highlight keyword feature + associated tests --- dist/filtergrid.css | 2 +- src-es6/modules/highlightKeywords.js | 108 +++++++++++++++++++++ src/core.js | 139 ++++++--------------------- src/end.frag | 4 - src/index.html | 12 +-- src/start.frag | 10 -- test/test-grid-layout.js | 23 ++--- test/test-store.js | 14 +-- 8 files changed, 161 insertions(+), 151 deletions(-) create mode 100644 src-es6/modules/highlightKeywords.js delete mode 100644 src/end.frag delete mode 100644 src/start.frag diff --git a/dist/filtergrid.css b/dist/filtergrid.css index ca6056de..daf9a291 100644 --- a/dist/filtergrid.css +++ b/dist/filtergrid.css @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------ - TableFilter stylesheet by Max Guglielmi - - (build date: Fri Dec 05 2014 11:24:29) + - (build date: Sat Dec 13 2014 20:02:51) - Edit below for your projects' needs ------------------------------------------------------------------------*/ diff --git a/src-es6/modules/highlightKeywords.js b/src-es6/modules/highlightKeywords.js new file mode 100644 index 00000000..4beff005 --- /dev/null +++ b/src-es6/modules/highlightKeywords.js @@ -0,0 +1,108 @@ +import {Dom} from '../dom'; +import {Str} from '../string'; + +export class HighlightKeyword{ + + /** + * HighlightKeyword, highlight matched keyword + * @param {Object} tf TableFilter instance + */ + constructor(tf) { + var f = tf.fObj; + //defines css class for highlighting + this.highlightCssClass = f.highlight_css_class || 'keyword'; + this.highlightedNodes = []; + + this.tf = tf; + } + + /** + * highlight occurences of searched term in passed node + * @param {Node} node + * @param {String} word Searched term + * @param {String} cssClass Css class name + */ + highlight(node, word, cssClass){ + // Iterate into this nodes childNodes + if(node.hasChildNodes){ + var children = node.childNodes; + for(var i=0; i