Fixed JavaScript sorting of tables with cells containing an input field

pull/186/head
luccioman 7 years ago
parent 3885fd64a0
commit 5c6c61809a

@ -3,7 +3,7 @@
version 2 version 2
7th April 2007 7th April 2007
Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/
fixed for YaCy 20th September 2016 fixed for YaCy 20th September 2016, 28th June 2018
Instructions: Instructions:
Download this file Download this file
@ -260,8 +260,10 @@ sorttable = {
hasInputs = (typeof node.getElementsByTagName == 'function') && hasInputs = (typeof node.getElementsByTagName == 'function') &&
node.getElementsByTagName('input').length; node.getElementsByTagName('input').length;
if (node.nodeName.toLowerCase() == 'input') {
if (node.getAttribute("sorttable_customkey") != null) { return node.value.replace(/^\s+|\s+$/g, '');
}
else if (node.getAttribute && node.getAttribute("sorttable_customkey") != null) {
return node.getAttribute("sorttable_customkey"); return node.getAttribute("sorttable_customkey");
} }
else if (typeof node.textContent != 'undefined' && !hasInputs) { else if (typeof node.textContent != 'undefined' && !hasInputs) {
@ -272,18 +274,14 @@ sorttable = {
} }
else if (typeof node.text != 'undefined' && !hasInputs) { else if (typeof node.text != 'undefined' && !hasInputs) {
return node.text.replace(/^\s+|\s+$/g, ''); return node.text.replace(/^\s+|\s+$/g, '');
} } else {
else {
switch (node.nodeType) { switch (node.nodeType) {
case 3: case 3: // Node.TEXT_NODE
if (node.nodeName.toLowerCase() == 'input') { case 4: // Node.CDATA_SECTION_NODE
return node.value.replace(/^\s+|\s+$/g, '');
}
case 4:
return node.nodeValue.replace(/^\s+|\s+$/g, ''); return node.nodeValue.replace(/^\s+|\s+$/g, '');
break; break;
case 1: case 1: // Node.ELEMENT_NODE
case 11: case 11: // Node.DOCUMENT_FRAGMENT_NODE
var innerText = ''; var innerText = '';
for (var i = 0; i < node.childNodes.length; i++) { for (var i = 0; i < node.childNodes.length; i++) {
innerText += sorttable.getInnerText(node.childNodes[i]); innerText += sorttable.getInnerText(node.childNodes[i]);

Loading…
Cancel
Save