Comparing version 2.2.0 to 2.2.2
{ | ||
"name": "tablesort", | ||
"description": "A sorting component for HTML tables", | ||
"version": "2.2.0", | ||
"version": "2.2.2", | ||
"author": "tristen <@fallsemo>", | ||
@@ -6,0 +6,0 @@ "ender": "./ender.js", |
@@ -78,2 +78,3 @@ ;(function() { | ||
item = '', | ||
items = [], | ||
i = that.getFirstDataRowIndex(); | ||
@@ -83,8 +84,8 @@ | ||
while (item === '' && i < t.tBodies[0].rows.length) { | ||
while (items.length < 3 && i < t.tBodies[0].rows.length) { | ||
item = getInnerText(t.tBodies[0].rows[i].cells[column]); | ||
item = item.trim(); | ||
// Exclude cell values where commented out HTML exists | ||
if (item.substr(0, 4) === '<!--' || item.length === 0) { | ||
item = ''; | ||
if (item.substr(0, 4) !== '<!--' && item.length !== 0) { | ||
items.push(item); | ||
} | ||
@@ -94,3 +95,3 @@ i++; | ||
if (item === '') return; | ||
if (!items) return; | ||
@@ -132,4 +133,4 @@ // Possible sortFunction scenarios | ||
if (aai == bbi) continue; | ||
if (aai < bbi) return -1; | ||
if (aai > bbi) return 1; | ||
if (aai > bbi) return -1; | ||
if (aai < bbi) return 1; | ||
} | ||
@@ -146,17 +147,14 @@ return 0; | ||
// Sort dot separted numbers, e.g. ip addresses or version numbers | ||
if (/^(\d+\.)+\d+$/.test(item)) { | ||
// Sort dot separated numbers, e.g. ip addresses or version numbers | ||
if (items.every(testDotSeparatedNumbers)) { | ||
sortFunction = sortDotSep; | ||
} | ||
// sort filesize, e.g. "123.45 MB" | ||
else if (/^\d+(\.\d+)? ?(k|M|G|T|P|E|Z|Y)?i?B?$/i.test(item)) { | ||
else if (items.every(testFilesize)) { | ||
sortFunction = sortFilesize; | ||
} | ||
// Sort as number if a currency key exists or number | ||
else if (item.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/) || // prefixed currency | ||
item.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/) || // suffixed currency | ||
item.match(/^-?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/) // number | ||
) { | ||
else if (items.every(testNumber)) { | ||
sortFunction = sortNumber; | ||
} else if (testDate(item)) { | ||
} else if (items.every(testDate)) { | ||
sortFunction = sortDate; | ||
@@ -254,2 +252,6 @@ } else { | ||
} | ||
// callback | ||
if (that.options.callback && typeof that.options.callback === 'function') { | ||
that.options.callback(header); | ||
} | ||
}, | ||
@@ -271,2 +273,16 @@ | ||
var testDotSeparatedNumbers = function(item){ | ||
return /^(\d+\.)+\d+$/.test(item); | ||
}; | ||
var testFilesize = function(item){ | ||
return /^\d+(\.\d+)? ?(k|M|G|T|P|E|Z|Y)?i?B?$/i.test(item); | ||
}; | ||
var testNumber = function(item){ | ||
return item.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/) || // prefixed currency | ||
item.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/) || // suffixed currency | ||
item.match(/^-?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/); // number | ||
}; | ||
var testDate = function(date) { | ||
@@ -273,0 +289,0 @@ return ( |
/*! | ||
* tablesort v2.2.0 (2015-01-18) | ||
* tablesort v2.2.2 (2015-02-01) | ||
* http://tristen.ca/tablesort/demo | ||
* Copyright (c) 2015 ; Licensed MIT | ||
*/!function(){function a(a,b){if(!a)throw new Error("Element not found");if("TABLE"!==a.tagName)throw new Error("Element must be a table");this.init(a,b||{})}a.prototype={init:function(a,d){var e,f=this;if(this.thead=!1,this.options=d,a.rows&&a.rows.length>0&&(a.tHead&&a.tHead.rows.length>0?(e=a.tHead.rows[a.tHead.rows.length-1],f.thead=!0):e=a.rows[0]),e){for(var g,h=function(){f.current&&f.current!==this&&(f.current.classList.contains(b)?f.current.classList.remove(b):f.current.classList.contains(c)&&f.current.classList.remove(c)),f.current=this,f.sortTable(this)},i=0;i<e.cells.length;i++){var j=e.cells[i];j.classList.contains("no-sort")||(j.classList.add("sort-header"),j.addEventListener("click",h,!1),j.classList.contains("sort-default")&&(g=j))}g&&(f.current=g,f.sortTable(g,!0))}},getFirstDataRowIndex:function(){return this.thead?0:1},sortTable:function(a,d){var e,f=this,m=a.cellIndex,n=i(a,"table"),o="",p=f.getFirstDataRowIndex();if(!(n.rows.length<=1)){for(;""===o&&p<n.tBodies[0].rows.length;)o=j(n.tBodies[0].rows[p].cells[m]),o=o.trim(),("<!--"===o.substr(0,4)||0===o.length)&&(o=""),p++;if(""!==o){var q=function(a,b){var c=j(a.cells[f.col]).toLowerCase(),d=j(b.cells[f.col]).toLowerCase();return c===d?0:d>c?1:-1},r=function(a,b){var c=j(a.cells[f.col]),d=j(b.cells[f.col]);return c=l(c),d=l(d),k(d,c)},s=function(a,b){var c=j(a.cells[f.col]).toLowerCase(),d=j(b.cells[f.col]).toLowerCase();return h(d)-h(c)},t=function(a,b){for(var c=j(a.cells[f.col]).split("."),d=j(b.cells[f.col]).split("."),e=0,g=c.length;g>e;e++){var h=parseInt(c[e]),i=parseInt(d[e]);if(h!=i){if(i>h)return-1;if(h>i)return 1}}return 0},u=function(a,b){var c=filesize2num(j(a.cells[f.col]));return bb=filesize2num(j(b.cells[f.col])),k(bb,c)};e=/^(\d+\.)+\d+$/.test(o)?t:/^\d+(\.\d+)? ?(k|M|G|T|P|E|Z|Y)?i?B?$/i.test(o)?u:o.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/)||o.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/)||o.match(/^-?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/)?r:g(o)?s:q,this.col=m;var v,w=[],x={},y=0;for(p=0;p<n.tBodies.length;p++)for(v=0;v<n.tBodies[p].rows.length;v++){var z=n.tBodies[p].rows[v];z.classList.contains("no-sort")?x[y]=z:w.push({tr:z,index:y}),y++}var A=f.options.descending?c:b,B=f.options.descending?b:c;d?a.classList.contains(A)||a.classList.contains(B)||a.classList.add(A):a.classList.contains(A)?(a.classList.remove(A),a.classList.add(B)):(a.classList.remove(B),a.classList.add(A));var C=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?b.index-c.index:d}},D=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?c.index-b.index:d}};a.classList.contains(c)?(w.sort(D(e)),w.reverse()):w.sort(C(e));var E=0;for(p=0;y>p;p++){var F;x[p]?(F=x[p],E++):F=w[p-E].tr,n.tBodies[0].appendChild(F)}}}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}};var b="sort-up",c="sort-down",d=/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,e=/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,f=/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i,g=function(a){return-1!==(-1!==a.search(d)||-1!==a.search(e)||a.search(-1!==f))&&!isNaN(h(a))},h=function(a){return a=a.replace(/\-/g,"/"),a=a.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3"),new Date(a).getTime()},i=function(a,b){return null===a?null:1===a.nodeType&&a.tagName.toLowerCase()===b.toLowerCase()?a:i(a.parentNode,b)},j=function(a){var b=this;if("string"==typeof a||"undefined"==typeof a)return a;var c=a.getAttribute("data-sort")||"";if(c)return c;if(a.textContent)return a.textContent;if(a.innerText)return a.innerText;for(var d=a.childNodes,e=d.length,f=0;e>f;f++)switch(d[f].nodeType){case 1:c+=b.getInnerText(d[f]);break;case 3:c+=d[f].nodeValue}return c},k=function(a,b){var c=parseFloat(a),d=parseFloat(b);return a=isNaN(c)?0:c,b=isNaN(d)?0:d,a-b},l=function(a){return a.replace(/[^\-?0-9.]/g,"")};filesize2num=function(a){var b=a.match(/^(\d+(\.\d+)?) ?((k|M|G|T|P|E|Z|Y)?i?B?)$/i),c=parseFloat(l(b[1])),d=b[3];return c*suffix2num(d)},suffix2num=function(a){a=a.toLowerCase();var b="i"===a[1]?1024:1e3;switch(a[0]){case"k":return Math.pow(b,2);case"m":return Math.pow(b,3);case"g":return Math.pow(b,4);case"t":return Math.pow(b,5);case"p":return Math.pow(b,6);case"e":return Math.pow(b,7);case"z":return Math.pow(b,8);case"y":return Math.pow(b,9);default:return b}},"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}(); | ||
*/!function(){function a(a,b){if(!a)throw new Error("Element not found");if("TABLE"!==a.tagName)throw new Error("Element must be a table");this.init(a,b||{})}a.prototype={init:function(a,d){var e,f=this;if(this.thead=!1,this.options=d,a.rows&&a.rows.length>0&&(a.tHead&&a.tHead.rows.length>0?(e=a.tHead.rows[a.tHead.rows.length-1],f.thead=!0):e=a.rows[0]),e){for(var g,h=function(){f.current&&f.current!==this&&(f.current.classList.contains(b)?f.current.classList.remove(b):f.current.classList.contains(c)&&f.current.classList.remove(c)),f.current=this,f.sortTable(this)},i=0;i<e.cells.length;i++){var j=e.cells[i];j.classList.contains("no-sort")||(j.classList.add("sort-header"),j.addEventListener("click",h,!1),j.classList.contains("sort-default")&&(g=j))}g&&(f.current=g,f.sortTable(g,!0))}},getFirstDataRowIndex:function(){return this.thead?0:1},sortTable:function(a,d){var e,f=this,p=a.cellIndex,q=l(a,"table"),r="",s=[],t=f.getFirstDataRowIndex();if(!(q.rows.length<=1)){for(;s.length<3&&t<q.tBodies[0].rows.length;)r=m(q.tBodies[0].rows[t].cells[p]),r=r.trim(),"<!--"!==r.substr(0,4)&&0!==r.length&&s.push(r),t++;if(s){var u=function(a,b){var c=m(a.cells[f.col]).toLowerCase(),d=m(b.cells[f.col]).toLowerCase();return c===d?0:d>c?1:-1},v=function(a,b){var c=m(a.cells[f.col]),d=m(b.cells[f.col]);return c=o(c),d=o(d),n(d,c)},w=function(a,b){var c=m(a.cells[f.col]).toLowerCase(),d=m(b.cells[f.col]).toLowerCase();return k(d)-k(c)},x=function(a,b){for(var c=m(a.cells[f.col]).split("."),d=m(b.cells[f.col]).split("."),e=0,g=c.length;g>e;e++){var h=parseInt(c[e]),i=parseInt(d[e]);if(h!=i){if(h>i)return-1;if(i>h)return 1}}return 0},y=function(a,b){var c=filesize2num(m(a.cells[f.col]));return bb=filesize2num(m(b.cells[f.col])),n(bb,c)};e=s.every(g)?x:s.every(h)?y:s.every(i)?v:s.every(j)?w:u,this.col=p;var z,A=[],B={},C=0;for(t=0;t<q.tBodies.length;t++)for(z=0;z<q.tBodies[t].rows.length;z++){var D=q.tBodies[t].rows[z];D.classList.contains("no-sort")?B[C]=D:A.push({tr:D,index:C}),C++}var E=f.options.descending?c:b,F=f.options.descending?b:c;d?a.classList.contains(E)||a.classList.contains(F)||a.classList.add(E):a.classList.contains(E)?(a.classList.remove(E),a.classList.add(F)):(a.classList.remove(F),a.classList.add(E));var G=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?b.index-c.index:d}},H=function(a){return function(b,c){var d=a(b.tr,c.tr);return 0===d?c.index-b.index:d}};a.classList.contains(c)?(A.sort(H(e)),A.reverse()):A.sort(G(e));var I=0;for(t=0;C>t;t++){var J;B[t]?(J=B[t],I++):J=A[t-I].tr,q.tBodies[0].appendChild(J)}f.options.callback&&"function"==typeof f.options.callback&&f.options.callback(a)}}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}};var b="sort-up",c="sort-down",d=/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,e=/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,f=/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i,g=function(a){return/^(\d+\.)+\d+$/.test(a)},h=function(a){return/^\d+(\.\d+)? ?(k|M|G|T|P|E|Z|Y)?i?B?$/i.test(a)},i=function(a){return a.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/)||a.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/)||a.match(/^-?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/)},j=function(a){return-1!==(-1!==a.search(d)||-1!==a.search(e)||a.search(-1!==f))&&!isNaN(k(a))},k=function(a){return a=a.replace(/\-/g,"/"),a=a.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3"),new Date(a).getTime()},l=function(a,b){return null===a?null:1===a.nodeType&&a.tagName.toLowerCase()===b.toLowerCase()?a:l(a.parentNode,b)},m=function(a){var b=this;if("string"==typeof a||"undefined"==typeof a)return a;var c=a.getAttribute("data-sort")||"";if(c)return c;if(a.textContent)return a.textContent;if(a.innerText)return a.innerText;for(var d=a.childNodes,e=d.length,f=0;e>f;f++)switch(d[f].nodeType){case 1:c+=b.getInnerText(d[f]);break;case 3:c+=d[f].nodeValue}return c},n=function(a,b){var c=parseFloat(a),d=parseFloat(b);return a=isNaN(c)?0:c,b=isNaN(d)?0:d,a-b},o=function(a){return a.replace(/[^\-?0-9.]/g,"")};filesize2num=function(a){var b=a.match(/^(\d+(\.\d+)?) ?((k|M|G|T|P|E|Z|Y)?i?B?)$/i),c=parseFloat(o(b[1])),d=b[3];return c*suffix2num(d)},suffix2num=function(a){a=a.toLowerCase();var b="i"===a[1]?1024:1e3;switch(a[0]){case"k":return Math.pow(b,2);case"m":return Math.pow(b,3);case"g":return Math.pow(b,4);case"t":return Math.pow(b,5);case"p":return Math.pow(b,6);case"e":return Math.pow(b,7);case"z":return Math.pow(b,8);case"y":return Math.pow(b,9);default:return b}},"undefined"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253684
17
6582