Comparing version 1.0.2 to 1.0.3
@@ -604,3 +604,3 @@ /*! | ||
// tablesort.js | ||
// tristen @fallsemoq | ||
// tristen @fallsemo | ||
@@ -632,3 +632,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'); | ||
@@ -650,3 +650,2 @@ for (var i = 0; i < siblings.length; i++) { | ||
var t = this.getParent(header, 'table'); | ||
var sortCaseInsensitive = function(a, b) { | ||
@@ -770,8 +769,11 @@ 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) }); | ||
} | ||
} | ||
@@ -778,0 +780,0 @@ }; |
{ | ||
"name": "tablesort", | ||
"description": "tablesort BRAP tablesort BRAP", | ||
"version": "1.0.2", | ||
"authors": ["tristen <@fallsemo>"], | ||
"version": "1.0.3", | ||
"author": "tristen <@fallsemo>", | ||
"main": "./tablesort.js", | ||
"ender": "./ender.js" | ||
"ender": "./ender.js", | ||
"homepage": "http://tristen.ca/tablesort/demo", | ||
"contributors": [ | ||
"Olivier Vaillancourt <@ovaillancourt>" | ||
], | ||
"licenses": [{ | ||
"type": "BSD" | ||
}], | ||
"devDependencies": { | ||
"jshint": "0.5.x", | ||
"uglify-js": "1.0.x" | ||
} | ||
} |
@@ -7,3 +7,3 @@ # tablesort.js | ||
```html | ||
``` html | ||
<script src='tablesort.min.js'></script> | ||
@@ -33,2 +33,11 @@ <script> | ||
## Building | ||
Developers can rebuild the minified library by running: | ||
``` bash | ||
npm install --dev | ||
make | ||
``` | ||
## TODOs | ||
@@ -35,0 +44,0 @@ |
@@ -27,3 +27,3 @@ // tablesort.js | ||
var cell = firstRow.cells[i]; | ||
cell.className = 'sort-header'; | ||
cell.className += ' sort-header'; | ||
this.addEvent(cell, 'click', function(e) { | ||
@@ -35,3 +35,5 @@ // Delete any sort classes on table headers that are not the current one. | ||
if (siblings[i] !== this) { | ||
siblings[i].className = siblings[i].className.replace(/ sort-\w+/, ''); | ||
siblings[i].className = siblings[i].className | ||
.replace(' sort-up', '') | ||
.replace(' sort-down', ''); | ||
} | ||
@@ -160,4 +162,4 @@ } | ||
}, | ||
cleanNumber: function(s) { | ||
return s.replace(/[^-?0-9.]/g, ''); | ||
cleanNumber: function(i) { | ||
return i.replace(/[^-?0-9.]/g, ''); | ||
}, | ||
@@ -164,0 +166,0 @@ hasClass: function(el, c) { |
// tablesort.js | ||
// 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)}} | ||
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)return;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-up","").replace(" sort-down",""));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]);return e=b.cleanNumber(e),b.compareNumber(d,e)};if(d.rows.length<=1)return;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);return b=isNaN(b)?0:b,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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
55729
10
1046
1
49
0
2