Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tablesort

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tablesort - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

demo/ender.js

@@ -785,3 +785,3 @@ /*!

});
};
}
}, true);

@@ -788,0 +788,0 @@ }(ender);

{
"name": "tablesort",
"description": "tablesort BRAP tablesort BRAP",
"version": "1.0.1",
"version": "1.0.2",
"authors": ["tristen <@fallsemo>"],

@@ -6,0 +6,0 @@ "main": "./tablesort.js",

@@ -5,3 +5,3 @@ # tablesort.js

## Basic Usage
## Basic usage

@@ -15,3 +15,3 @@ ```html

## Supported features
## Features

@@ -18,0 +18,0 @@ * Sort strings

// tablesort.js
// tristen @fallsemoq
// tristen @fallsemo

@@ -29,3 +29,3 @@ function Tablesort(el) {

this.addEvent(cell, 'click', function(e) {
//Delete any sort classes on table headers that are not the current one.
// Delete any sort classes on table headers that are not the current one.
var siblings = that.getParent(cell, 'tr').getElementsByTagName('th');

@@ -47,3 +47,2 @@ for (var i = 0; i < siblings.length; i++) {

var t = this.getParent(header, 'table');
var sortCaseInsensitive = function(a, b) {

@@ -167,9 +166,12 @@ var aa = that.getInnerText(a.cells[that.col]).toLowerCase();

},
// cross-browser events
// http://ejohn.org/apps/jselect/event.html
addEvent: function(object, event, method) {
if (object.addEventListener)
if (object.attachEvent) {
object['e' + event + method] = method;
object[event + method] = function(){object['e' + event + method](window.event);}
object.attachEvent('on' + event, object[event + method]);
} else {
object.addEventListener(event, method, false);
else if (object.attachEvent)
object.attachEvent('on' + event, function(){ method(window.event) });
}
}
};
// tablesort.js
// tristen @fallsemoq
function Tablesort(a){a.tagName==="TABLE"?this.init(a):console.error("Element must be a table")}Tablesort.prototype={thead:!1,col:undefined,init:function(a){var b=this,c;a.rows&&a.rows.length>0&&(a.tHead&&a.tHead.rows.length>0?(c=a.tHead.rows[a.tHead.rows.length-1],b.thead=!0):c=a.rows[0]);if(!!c)for(var d=0;d<c.cells.length;d++){var e=c.cells[d];e.className="sort-header",this.addEvent(e,"click",function(a){var c=b.getParent(e,"tr").getElementsByTagName("th");for(var d=0;d<c.length;d++)(b.hasClass(c[d],"sort-up")||b.hasClass(c[d],"sort-down"))&&c[d]!==this&&(c[d].className=c[d].className.replace(/ sort-\w+/,""));b.sortTable(this)})}},sortTable:function(a){var b=this,c=a.cellIndex,d=this.getParent(a,"table"),e=function(a,c){var d=b.getInnerText(a.cells[b.col]).toLowerCase(),e=b.getInnerText(c.cells[b.col]).toLowerCase();return d===e?0:d<e?-1:1},f=function(a,c){var d=b.getInnerText(a.cells[b.col]);d=b.cleanNumber(d);var e=b.getInnerText(c.cells[b.col]);e=b.cleanNumber(e);return b.compareNumber(d,e)};if(!(d.rows.length<=1)){var g="",h=0;while(g===""&&h<d.tBodies[0].rows.length){var g=b.getInnerText(d.tBodies[0].rows[h].cells[c]);g=b.trim(g);if(g.substr(0,4)==="<!--"||g.length===0)g="";h++}if(g==="")return;var i;g.match(/^-?[£$€Û¢´]\d/)||g.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)?i=f:i=e,this.col=c;var j=[],k=[];for(var l=0;l<d.tBodies.length;l++)for(var h=0;h<d.tBodies[l].rows[0].length;h++)j[h]=d.tBodies[l].rows[0][h];for(var l=0;l<d.tBodies.length;l++)if(!b.thead)for(var m=1;m<d.tBodies[l].rows.length;m++)k[m-1]=d.tBodies[l].rows[m];else for(var m=0;m<d.tBodies[l].rows.length;m++)k[m]=d.tBodies[l].rows[m];k.sort(i),b.hasClass(a,"sort-up")?(a.className=a.className.replace(/ sort-up/,""),a.className+=" sort-down"):(a.className=a.className.replace(/ sort-down/,""),a.className+=" sort-up",k.reverse());for(var h=0;h<k.length;h++)k[h].className||d.tBodies[0].appendChild(k[h])}},getInnerText:function(a){var b=this;if(typeof a=="string"||typeof a=="undefined")return a;if(a.innerText)return a.innerText;var c="",d=a.childNodes,e=d.length;for(var f=0;f<e;f++)switch(d[f].nodeType){case 1:c+=b.getInnerText(d[f]);break;case 3:c+=d[f].nodeValue}return c},getParent:function(a,b){return a===null?null:a.nodeType===1&&a.tagName.toLowerCase()===b.toLowerCase()?a:this.getParent(a.parentNode,b)},compareNumber:function(a,b){var a=parseFloat(a);a=isNaN(a)?0:a;var b=parseFloat(b);b=isNaN(b)?0:b;return a-b},trim:function(a){return a.replace(/^\s+|\s+$/g,"")},cleanNumber:function(a){return a.replace(/[^-?0-9.]/g,"")},hasClass:function(a,b){return(" "+a.className+" ").indexOf(" "+b+" ")>-1},addEvent:function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,function(){c(window.event)})}}
// tristen @fallsemo
function Tablesort(a){a.tagName==="TABLE"?this.init(a):console.error("Element must be a table")}Tablesort.prototype={thead:!1,col:undefined,init:function(a){var b=this,c;a.rows&&a.rows.length>0&&(a.tHead&&a.tHead.rows.length>0?(c=a.tHead.rows[a.tHead.rows.length-1],b.thead=!0):c=a.rows[0]);if(!!c)for(var d=0;d<c.cells.length;d++){var e=c.cells[d];e.className="sort-header",this.addEvent(e,"click",function(a){var c=b.getParent(e,"tr").getElementsByTagName("th");for(var d=0;d<c.length;d++)(b.hasClass(c[d],"sort-up")||b.hasClass(c[d],"sort-down"))&&c[d]!==this&&(c[d].className=c[d].className.replace(/ sort-\w+/,""));b.sortTable(this)})}},sortTable:function(a){var b=this,c=a.cellIndex,d=this.getParent(a,"table"),e=function(a,c){var d=b.getInnerText(a.cells[b.col]).toLowerCase(),e=b.getInnerText(c.cells[b.col]).toLowerCase();return d===e?0:d<e?-1:1},f=function(a,c){var d=b.getInnerText(a.cells[b.col]);d=b.cleanNumber(d);var e=b.getInnerText(c.cells[b.col]);e=b.cleanNumber(e);return b.compareNumber(d,e)};if(!(d.rows.length<=1)){var g="",h=0;while(g===""&&h<d.tBodies[0].rows.length){var g=b.getInnerText(d.tBodies[0].rows[h].cells[c]);g=b.trim(g);if(g.substr(0,4)==="<!--"||g.length===0)g="";h++}if(g==="")return;var i;g.match(/^-?[£$€Û¢´]\d/)||g.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)?i=f:i=e,this.col=c;var j=[],k=[];for(var l=0;l<d.tBodies.length;l++)for(var h=0;h<d.tBodies[l].rows[0].length;h++)j[h]=d.tBodies[l].rows[0][h];for(var l=0;l<d.tBodies.length;l++)if(!b.thead)for(var m=1;m<d.tBodies[l].rows.length;m++)k[m-1]=d.tBodies[l].rows[m];else for(var m=0;m<d.tBodies[l].rows.length;m++)k[m]=d.tBodies[l].rows[m];k.sort(i),b.hasClass(a,"sort-up")?(a.className=a.className.replace(/ sort-up/,""),a.className+=" sort-down"):(a.className=a.className.replace(/ sort-down/,""),a.className+=" sort-up",k.reverse());for(var h=0;h<k.length;h++)k[h].className||d.tBodies[0].appendChild(k[h])}},getInnerText:function(a){var b=this;if(typeof a=="string"||typeof a=="undefined")return a;if(a.innerText)return a.innerText;var c="",d=a.childNodes,e=d.length;for(var f=0;f<e;f++)switch(d[f].nodeType){case 1:c+=b.getInnerText(d[f]);break;case 3:c+=d[f].nodeValue}return c},getParent:function(a,b){return a===null?null:a.nodeType===1&&a.tagName.toLowerCase()===b.toLowerCase()?a:this.getParent(a.parentNode,b)},compareNumber:function(a,b){var a=parseFloat(a);a=isNaN(a)?0:a;var b=parseFloat(b);b=isNaN(b)?0:b;return a-b},trim:function(a){return a.replace(/^\s+|\s+$/g,"")},cleanNumber:function(a){return a.replace(/[^-?0-9.]/g,"")},hasClass:function(a,b){return(" "+a.className+" ").indexOf(" "+b+" ")>-1},addEvent:function(a,b,c){a.attachEvent?(a["e"+b+c]=c,a[b+c]=function(){a["e"+b+c](window.event)},a.attachEvent("on"+b,a[b+c])):a.addEventListener(b,c,!1)}}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc