mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-03 06:22:34 +02:00
191 lines
7.7 KiB
HTML
191 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<base data-ice="baseUrl" href="../../../">
|
|
<title data-ice="title">src/modules/highlightKeywords.js | TableFilter v0.0.0 API Document</title>
|
|
<link type="text/css" rel="stylesheet" href="css/style.css">
|
|
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
|
|
<script src="script/prettify/prettify.js"></script>
|
|
|
|
|
|
</head>
|
|
<body class="layout-container">
|
|
|
|
<header>
|
|
<a href="./">Home</a>
|
|
<a href="identifiers.html">Identifier</a>
|
|
<a href="source.html">Source</a>
|
|
|
|
<a data-ice="repoURL" href="https://github.com/koalyptus/TableFilter.git" class="repo-url-github">Repository</a>
|
|
<div class="search-box">
|
|
<span>
|
|
<img src="./image/search.png">
|
|
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
|
|
</span>
|
|
<ul class="search-result"></ul>
|
|
</div>
|
|
</header>
|
|
|
|
<nav class="navigation" data-ice="nav"><div data-ice="classWrap">
|
|
<h2>Class</h2>
|
|
<ul>
|
|
|
|
<li data-ice="classDoc"><span><a href="class/src/extensions/advancedGrid/adapterEzEditTable.js~AdapterEzEditTable.html">AdapterEzEditTable</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/extensions/sort/adapterSortabletable.js~AdapterSortableTable.html">AdapterSortableTable</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/alternateRows.js~AlternateRows.html">AlternateRows</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/checkList.js~CheckList.html">CheckList</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/clearButton.js~ClearButton.html">ClearButton</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/extensions/colOps/colOps.js~ColOps.html">ColOps</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/extensions/colsVisibility/colsVisibility.js~ColsVisibility.html">ColsVisibility</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/dropdown.js~Dropdown.html">Dropdown</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/extensions/filtersVisibility/filtersVisibility.js~FiltersVisibility.html">FiltersVisibility</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/gridLayout.js~GridLayout.html">GridLayout</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/help.js~Help.html">Help</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/highlightKeywords.js~HighlightKeyword.html">HighlightKeyword</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/loader.js~Loader.html">Loader</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/paging.js~Paging.html">Paging</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/popupFilter.js~PopupFilter.html">PopupFilter</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/rowsCounter.js~RowsCounter.html">RowsCounter</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/statusBar.js~StatusBar.html">StatusBar</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/modules/store.js~Store.html">Store</a></span></li>
|
|
<li data-ice="classDoc"><span><a href="class/src/tablefilter.js~TableFilter.html">TableFilter</a></span></li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</nav>
|
|
|
|
<div class="content" data-ice="content"><h1 data-ice="title">src/modules/highlightKeywords.js</h1>
|
|
<pre class="source-code line-number"><code class="prettyprint linenums" data-ice="content">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.config();
|
|
//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<children.length; i++){
|
|
this.highlight(children[i], word, cssClass);
|
|
}
|
|
}
|
|
|
|
if(node.nodeType === 3){
|
|
var tempNodeVal = Str.lower(node.nodeValue);
|
|
var tempWordVal = Str.lower(word);
|
|
if(tempNodeVal.indexOf(tempWordVal) != -1){
|
|
var pn = node.parentNode;
|
|
if(pn && pn.className != cssClass){
|
|
// word not highlighted yet
|
|
var nv = node.nodeValue,
|
|
ni = tempNodeVal.indexOf(tempWordVal),
|
|
// Create a load of replacement nodes
|
|
before = Dom.text(nv.substr(0, ni)),
|
|
docWordVal = nv.substr(ni,word.length),
|
|
after = Dom.text(nv.substr(ni+word.length)),
|
|
hiwordtext = Dom.text(docWordVal),
|
|
hiword = Dom.create('span');
|
|
hiword.className = cssClass;
|
|
hiword.appendChild(hiwordtext);
|
|
pn.insertBefore(before,node);
|
|
pn.insertBefore(hiword,node);
|
|
pn.insertBefore(after,node);
|
|
pn.removeChild(node);
|
|
this.highlightedNodes.push(hiword.firstChild);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Removes highlight to nodes matching passed string
|
|
* @param {String} word
|
|
* @param {String} cssClass Css class to remove
|
|
*/
|
|
unhighlight(word, cssClass){
|
|
var arrRemove = [];
|
|
var highlightedNodes = this.highlightedNodes;
|
|
for(var i=0; i<highlightedNodes.length; i++){
|
|
var n = highlightedNodes[i];
|
|
if(!n){
|
|
continue;
|
|
}
|
|
var tempNodeVal = Str.lower(n.nodeValue),
|
|
tempWordVal = Str.lower(word);
|
|
if(tempNodeVal.indexOf(tempWordVal) !== -1){
|
|
var pn = n.parentNode;
|
|
if(pn && pn.className === cssClass){
|
|
var prevSib = pn.previousSibling,
|
|
nextSib = pn.nextSibling;
|
|
if(!prevSib || !nextSib){ continue; }
|
|
nextSib.nodeValue = prevSib.nodeValue + n.nodeValue +
|
|
nextSib.nodeValue;
|
|
prevSib.nodeValue = '';
|
|
n.nodeValue = '';
|
|
arrRemove.push(i);
|
|
}
|
|
}
|
|
}
|
|
for(var k=0; k<arrRemove.length; k++){
|
|
highlightedNodes.splice(arrRemove[k], 1);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Clear all occurrences of highlighted nodes
|
|
*/
|
|
unhighlightAll(){
|
|
if(!this.tf.highlightKeywords || !this.tf.searchArgs){
|
|
return;
|
|
}
|
|
for(var y=0; y<this.tf.searchArgs.length; y++){
|
|
this.unhighlight(
|
|
this.tf.searchArgs[y], this.highlightCssClass);
|
|
}
|
|
this.highlightedNodes = [];
|
|
}
|
|
}</code></pre>
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.1.4)</span></a>
|
|
</footer>
|
|
|
|
<script src="script/search_index.js"></script>
|
|
<script src="script/search.js"></script>
|
|
<script src="script/pretty-print.js"></script>
|
|
<script src="script/inherited-summary.js"></script>
|
|
<script src="script/test-summary.js"></script>
|
|
<script src="script/inner-link.js"></script>
|
|
<script src="script/patch-for-local.js"></script>
|
|
</body>
|
|
</html>
|