mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-23 16:52:26 +02:00
Fixed bug in paging
This commit is contained in:
parent
26e6e01de6
commit
95ff4b6701
|
@ -153,7 +153,7 @@ export class Paging{
|
||||||
this.tf = tf;
|
this.tf = tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildUI{
|
buildUI(){
|
||||||
|
|
||||||
var slcPages;
|
var slcPages;
|
||||||
var tf = this.tf;
|
var tf = this.tf;
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
define(["exports", "../dom", "../string"], function (exports, _dom, _string) {
|
define(["exports", "../dom", "../string"], function (exports, _dom, _string) {
|
||||||
"use strict";
|
"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 Dom = _dom.Dom;
|
||||||
var Str = _string.Str;
|
var Str = _string.Str;
|
||||||
var HighlightKeyword = (function () {
|
var HighlightKeyword = (function () {
|
||||||
var HighlightKeyword = function HighlightKeyword(tf) {
|
var HighlightKeyword =
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HighlightKeyword, highlight matched keyword
|
||||||
|
* @param {Object} tf TableFilter instance
|
||||||
|
*/
|
||||||
|
function HighlightKeyword(tf) {
|
||||||
var f = tf.fObj;
|
var f = tf.fObj;
|
||||||
//defines css class for highlighting
|
//defines css class for highlighting
|
||||||
this.highlightCssClass = f.highlight_css_class || "keyword";
|
this.highlightCssClass = f.highlight_css_class || "keyword";
|
||||||
|
@ -18,83 +19,74 @@ define(["exports", "../dom", "../string"], function (exports, _dom, _string) {
|
||||||
this.tf = tf;
|
this.tf = tf;
|
||||||
};
|
};
|
||||||
|
|
||||||
_classProps(HighlightKeyword, null, {
|
HighlightKeyword.prototype.highlight = function (node, word, cssClass) {
|
||||||
highlight: {
|
// Iterate into this nodes childNodes
|
||||||
writable: true,
|
if (node.hasChildNodes) {
|
||||||
value: function (node, word, cssClass) {
|
var children = node.childNodes;
|
||||||
// Iterate into this nodes childNodes
|
for (var i = 0; i < children.length; i++) {
|
||||||
if (node.hasChildNodes) {
|
this.highlight(children[i], word, cssClass);
|
||||||
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 = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
HighlightKeyword.prototype.unhighlight = 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
HighlightKeyword.prototype.unhighlightAll = 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;
|
return HighlightKeyword;
|
||||||
})();
|
})();
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue