1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-13 03:46:41 +02:00

Added start and end frag files, removed by mistake

This commit is contained in:
Max Guglielmi 2014-12-14 15:55:01 +11:00
parent 0f4d81b9a5
commit 7daf5c7d0d
6 changed files with 223 additions and 6 deletions

2
dist/filtergrid.css vendored
View file

@ -1,6 +1,6 @@
/*------------------------------------------------------------------------
- TableFilter stylesheet by Max Guglielmi
- (build date: Sat Dec 13 2014 20:02:51)
- (build date: Sun Dec 14 2014 15:53:25)
- Edit below for your projects' needs
------------------------------------------------------------------------*/

10
dist/tablefilter.js vendored

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,103 @@
define(["exports", "../dom", "../string"], function (exports, _dom, _string) {
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Dom = _dom.Dom;
var Str = _string.Str;
var HighlightKeyword = (function () {
var HighlightKeyword = function HighlightKeyword(tf) {
var f = tf.fObj;
//defines css class for highlighting
this.highlightCssClass = f.highlight_css_class || "keyword";
this.highlightedNodes = [];
this.tf = tf;
};
_classProps(HighlightKeyword, null, {
highlight: {
writable: true,
value: function (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);
}
}
}
}
},
unhighlight: {
writable: true,
value: function (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);
}
}
},
unhighlightAll: {
writable: true,
value: function () {
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 = [];
}
}
});
return HighlightKeyword;
})();
exports.HighlightKeyword = HighlightKeyword;
});

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TableFilter basic test</title>
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th>From</th>
<th>Destination</th>
<th>Road Distance (km)</th>
<th>By Air (hrs)</th>
<th>By Rail (hrs)</th>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Adelaide</td>
<td>1412</td>
<td>1.4</td>
<td>25.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Brisbane</td>
<td>982</td>
<td>1.5</td>
<td>16</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Canberra</td>
<td>286</td>
<td>.6</td>
<td>4.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Melbourne</td>
<td>872</td>
<td>1.1</td>
<td>10.5</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Perth</td>
<td>2781</td>
<td>3.1</td>
<td>38</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Alice Springs</td>
<td>1533</td>
<td>2</td>
<td>20.25</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Brisbane</td>
<td>2045</td>
<td>2.15</td>
<td>40</td>
</tr>
</tbody>
</table>
<script data-main="test-highlight-keywords" src="../libs/requirejs/require.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

View file

@ -0,0 +1,31 @@
requirejs(['test-config', '../src/core'], function(config, TableFilter){
QUnit.start();
var dom = require('dom').Dom,
Highlight = require('modules/highlightKeywords').HighlightKeyword;
var tf = new TableFilter('demo', {
highlight_keywords: true
});
tf.init();
var highlightKeyword = tf.Cpt.highlightKeyword;
module('Sanity checks');
test('HighlightKeyword component', function() {
deepEqual(highlightKeyword instanceof Highlight, true, 'Instance of expected class type');
notEqual(highlightKeyword, null, 'Instanciated');
deepEqual(highlightKeyword.highlightedNodes instanceof Array, true, 'Property check');
});
test('Highlighted keywords', function() {
tf.SetFilterValue(1, 'Perth');
tf.SetFilterValue(3, '3.1');
tf._Filter();
deepEqual(highlightKeyword.highlightedNodes.length, 2, 'Number of highlighted words');
tf._ClearFilters();
tf._Filter();
deepEqual(highlightKeyword.highlightedNodes.length, 0, 'Number of highlighted words');
});
});