Skip to content
Browse files

Made grunt the build system, src now lint free

Build v1.6.0
  • Loading branch information...
1 parent 8965e59 commit 9cd3407643e4bdd08f7a92baa193fb7b2445d31e @cobbweb cobbweb committed Nov 7, 2012
Showing with 436 additions and 67 deletions.
  1. +1 −0 .gitignore
  2. +0 −5 Makefile
  3. +58 −0 grunt.js
  4. +5 −4 package.json
  5. +274 −0 src/tablesort.js
  6. +94 −54 tablesort.js
  7. +4 −4 tablesort.min.js
View
1 .gitignore
@@ -0,0 +1 @@
+node_modules
View
5 Makefile
@@ -1,5 +0,0 @@
-tablesort.min.js:
- ./node_modules/.bin/uglifyjs tablesort.js > tablesort.min.js
-
-lint:
- ./node_modules/.bin/jshint tablesort.js
View
58 grunt.js
@@ -0,0 +1,58 @@
+/*global module:false*/
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: '<json:package.json>',
+ meta: {
+ banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
+ '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
+ '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
+ '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
+ ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
+ },
+ lint: {
+ files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
+ },
+ qunit: {
+ files: ['test/**/*.html']
+ },
+ concat: {
+ dist: {
+ src: ['<banner:meta.banner>', '<file_strip_banner:src/<%= pkg.name %>.js>'],
+ dest: '<%= pkg.name %>.js'
+ }
+ },
+ min: {
+ dist: {
+ src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
+ dest: '<%= pkg.name %>.min.js'
+ }
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'lint qunit'
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ browser: true
+ },
+ globals: {}
+ },
+ uglify: {}
+ });
+
+ // Default task.
+ grunt.registerTask('default', 'lint qunit concat min');
+
+};
View
9 package.json
@@ -1,21 +1,22 @@
{
"name": "tablesort",
"description": "A sorting component for HTML tables",
- "version": "1.5.0",
+ "version": "1.6.0",
"author": "tristen <@fallsemo>",
- "main": "./tablesort.js",
"ender": "./ender.js",
"homepage": "http://tristen.ca/tablesort/demo",
"contributors": [
"Olivier Vaillancourt <@ovaillancourt>",
"Dmitry Kichenko <@imissmyjuno>",
- "Dong Liu <@dongliu>"
+ "Dong Liu <@dongliu>",
+ "Andrew Cobby <andrew.cobby@gmail.com>"
],
"licenses": [{
"type": "MIT"
}],
"devDependencies": {
"jshint": "0.5.x",
- "uglify-js": "1.0.x"
+ "uglify-js": "1.0.x",
+ "grunt": "0.3.x"
}
}
View
274 src/tablesort.js
@@ -0,0 +1,274 @@
+;(function () {
+ function Tablesort(el, options) {
+ if (el.tagName !== 'TABLE') {
+ throw new Error('Element must be a table');
+ }
+
+ this.init(el, options || {});
+ }
+
+ Tablesort.prototype = {
+
+ init: function(el, options) {
+ var that = this;
+ var firstRow;
+ this.thead = false;
+ this.options = options;
+ this.options.d = options.descending || false;
+
+ if (el.rows && el.rows.length > 0) {
+ if(el.tHead && el.tHead.rows.length > 0) {
+ firstRow = el.tHead.rows[el.tHead.rows.length - 1];
+ that.thead = true;
+ } else {
+ firstRow = el.rows[0];
+ }
+ }
+
+ if (!firstRow) {
+ return;
+ }
+
+ var onClick = function (e) {
+ // Delete sort classes on headers that are not the current one.
+ var siblings = getParent(cell, 'tr').getElementsByTagName('th');
+ for(var i = 0; i < siblings.length; i++) {
+ if(hasClass(siblings[i], 'sort-up') || hasClass(siblings[i], 'sort-down')) {
+ if(siblings[i] !== this) {
+ siblings[i].className = siblings[i].className.replace(' sort-down', '')
+ .replace(' sort-up', '');
+ }
+ }
+ }
+ that.current = this;
+ that.sortTable(this);
+ };
+
+ // Assume first row is the header and attach a click handler to eech.
+ for(var i = 0; i < firstRow.cells.length; i++) {
+ var cell = firstRow.cells[i];
+ if(!hasClass(cell, 'no-sort')) {
+ cell.className += ' sort-header';
+ addEvent(cell, 'click', onClick);
+ }
+ }
+ },
+
+ sortTable: function(header, update) {
+ var that = this;
+ var column = header.cellIndex;
+ var sortFunction;
+ var t = getParent(header, 'table');
+ var item = '', i = 0;
+
+ if (t.rows.length <= 1) {
+ return;
+ }
+
+
+ while (item === '' && i < t.tBodies[0].rows.length) {
+ item = getInnerText(t.tBodies[0].rows[i].cells[column]);
+ item = trim(item);
+ // Exclude cell values where commented out HTML exists
+ if(item.substr(0, 4) === '<!--' || item.length === 0) {
+ item = '';
+ }
+ i++;
+ }
+
+ if (item === '') {
+ return;
+ }
+
+ // Possible sortFunction scenarios
+ var sortCaseInsensitive = function (a, b) {
+ var aa = getInnerText(a.cells[that.col]).toLowerCase();
+ var bb = getInnerText(b.cells[that.col]).toLowerCase();
+
+ if(aa === bb) {
+ return 0;
+ }
+
+ if(aa < bb) {
+ return 1;
+ }
+
+ return -1;
+ };
+ var sortNumber = function (a, b) {
+ var aa = getInnerText(a.cells[that.col]);
+ aa = cleanNumber(aa);
+ var bb = getInnerText(b.cells[that.col]);
+ bb = cleanNumber(bb);
+ return compareNumber(bb, aa);
+ };
+ var sortDate = function(a, b) {
+ var aa = getInnerText(a.cells[that.col]).toLowerCase(),
+ bb = getInnerText(b.cells[that.col]).toLowerCase();
+ return parseDate(bb) - parseDate(aa);
+ };
+
+ // Sort as number if a currency key exists or number
+ if (item.match(/^-?\x24Û¢´]\d/) || item.match(/^-?(\d+[,\.]?)+(E[\-+][\d]+)?%?$/)) {
+ sortFunction = sortNumber;
+ } else if (testDate(item)) {
+ sortFunction = sortDate;
+ } else {
+ sortFunction = sortCaseInsensitive;
+ }
+
+ this.col = column;
+ var firstRow = [],
+ newRows = [],
+ k, j;
+
+ for (k = 0; k < t.tBodies.length; k++) {
+ for(i = 0; i < t.tBodies[k].rows[0].length; i++) {
+ firstRow[i] = t.tBodies[k].rows[0][i];
+ }
+ }
+ for (k = 0; k < t.tBodies.length; k++) {
+ if (!that.thead) {
+ // skip the first row
+ for(j = 1; j < t.tBodies[k].rows.length; j++) {
+ newRows[j - 1] = t.tBodies[k].rows[j];
+ }
+ } else {
+ // don't skip the first row
+ for(j = 0; j < t.tBodies[k].rows.length; j++) {
+ newRows[j] = t.tBodies[k].rows[j];
+ }
+ }
+ }
+ newRows.sort(sortFunction);
+
+ if (!update) {
+ if(that.options.d) {
+ if(hasClass(header, 'sort-up')) {
+ header.className = header.className.replace(/ sort-up/, '');
+ header.className += ' sort-down';
+ } else {
+ header.className = header.className.replace(/ sort-down/, '');
+ header.className += ' sort-up';
+ }
+ } else {
+ if(hasClass(header, 'sort-down')) {
+ header.className = header.className.replace(/ sort-down/, '');
+ header.className += ' sort-up';
+ } else {
+ header.className = header.className.replace(/ sort-up/, '');
+ header.className += ' sort-down';
+ }
+ }
+ }
+
+ // Before we append should we reverse the new array or not?
+ if(hasClass(header, 'sort-down')) {
+ newRows.reverse();
+ }
+
+ // append rows that already exist rather than creating new ones
+ for(i = 0; i < newRows.length; i++) {
+ // Don't sort on rows specified. TODO might want to
+ // do this more upstream.
+ if(!hasClass(newRows[i], 'no-sort')) {
+ t.tBodies[0].appendChild(newRows[i]);
+ }
+ }
+ },
+
+ refresh: function() {
+ if (this.current !== undefined) {
+ this.sortTable(this.current, true);
+ }
+ }
+ };
+
+ var week = /(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,
+ commonDate = /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,
+ month = /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i;
+
+ var testDate = function(date) {
+ return (
+ date.search(week) !== -1 ||
+ date.search(commonDate) !== -1 ||
+ date.search(month !== -1)
+ ) !== -1 ;
+ },
+ parseDate = function (date) {
+ date = date.replace(/\-/g, '/');
+ date = date.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, '$1/$2/$3'); // format before getTime
+ return new Date(date).getTime();
+ },
+ getParent = function (el, pTagName) {
+ if (el === null) {
+ return null;
+ } else if (el.nodeType === 1 && el.tagName.toLowerCase() === pTagName.toLowerCase()) {
+ return el;
+ } else {
+ return getParent(el.parentNode, pTagName);
+ }
+ },
+ getInnerText = function (el) {
+ var that = this;
+
+ if (typeof el === 'string' || typeof el === 'undefined') {
+ return el;
+ }
+ if (el.textContent) {
+ return el.textContent;
+ }
+ if (el.innerText) {
+ return el.innerText;
+ }
+
+ var str = '',
+ cs = el.childNodes,
+ l = cs.length;
+
+ for (var i = 0; i < l; i++) {
+ switch (cs[i].nodeType) {
+ case 1:
+ // ELEMENT_NODE
+ str += that.getInnerText(cs[i]);
+ break;
+ case 3:
+ // TEXT_NODE
+ str += cs[i].nodeValue;
+ break;
+ }
+ }
+
+ return str;
+ },
+ compareNumber = function (a, b) {
+ var aa = parseFloat(a);
+ a = isNaN(aa) ? 0 : aa;
+ var bb = parseFloat(b);
+ b = isNaN(bb) ? 0 : bb;
+ return a - b;
+ },
+ trim = function (s) {
+ return s.replace(/^\s+|\s+$/g, '');
+ },
+ cleanNumber = function (i) {
+ return i.replace(/[^\-?0-9.]/g, '');
+ },
+ hasClass = function (el, c) {
+ return(' ' + el.className + ' ').indexOf(' ' + c + ' ') > -1;
+ },
+ // http://ejohn.org/apps/jselect/event.html
+ addEvent = function (object, event, method) {
+ 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);
+ }
+ };
+
+ window.Tablesort = Tablesort;
+})();
View
148 tablesort.js
@@ -1,60 +1,76 @@
-// tablesort.js
-// Version: 1.5.0
-// Author: tristen @fallsemo
+/*! tablesort - v1.6.0 - 2012-11-07
+* http://tristen.ca/tablesort/demo
+* Copyright (c) 2012 ; Licensed MIT */
-(function () {
+;(function () {
function Tablesort(el, options) {
- el.tagName === 'TABLE' ? this.init(el, options || {}) : console.error('Element must be a table');
+ if (el.tagName !== 'TABLE') {
+ throw new Error('Element must be a table');
+ }
+
+ this.init(el, options || {});
}
Tablesort.prototype = {
- init: function (el, options) {
+
+ init: function(el, options) {
var that = this;
var firstRow;
this.thead = false;
this.options = options;
this.options.d = options.descending || false;
- if(el.rows && el.rows.length > 0) {
+ if (el.rows && el.rows.length > 0) {
if(el.tHead && el.tHead.rows.length > 0) {
firstRow = el.tHead.rows[el.tHead.rows.length - 1];
that.thead = true;
} else {
firstRow = el.rows[0];
}
}
- if(!firstRow) return;
+
+ if (!firstRow) {
+ return;
+ }
+
+ var onClick = function (e) {
+ // Delete sort classes on headers that are not the current one.
+ var siblings = getParent(cell, 'tr').getElementsByTagName('th');
+ for(var i = 0; i < siblings.length; i++) {
+ if(hasClass(siblings[i], 'sort-up') || hasClass(siblings[i], 'sort-down')) {
+ if(siblings[i] !== this) {
+ siblings[i].className = siblings[i].className.replace(' sort-down', '')
+ .replace(' sort-up', '');
+ }
+ }
+ }
+ that.current = this;
+ that.sortTable(this);
+ };
// Assume first row is the header and attach a click handler to eech.
for(var i = 0; i < firstRow.cells.length; i++) {
var cell = firstRow.cells[i];
if(!hasClass(cell, 'no-sort')) {
cell.className += ' sort-header';
- addEvent(cell, 'click', function (e) {
- // Delete sort classes on headers that are not the current one.
- var siblings = getParent(cell, 'tr').getElementsByTagName('th');
- for(var i = 0; i < siblings.length; i++) {
- if(hasClass(siblings[i], 'sort-up') || hasClass(siblings[i], 'sort-down')) {
- if(siblings[i] !== this) {
- siblings[i].className = siblings[i].className.replace(' sort-down', '')
- .replace(' sort-up', '');
- }
- }
- }
- that.current = this;
- that.sortTable(this);
- });
+ addEvent(cell, 'click', onClick);
}
}
},
- sortTable: function (header, update) {
+
+ sortTable: function(header, update) {
var that = this;
var column = header.cellIndex;
+ var sortFunction;
var t = getParent(header, 'table');
- if(t.rows.length <= 1) return;
-
var item = '', i = 0;
- while(item === '' && i < t.tBodies[0].rows.length) {
+
+ if (t.rows.length <= 1) {
+ return;
+ }
+
+
+ while (item === '' && i < t.tBodies[0].rows.length) {
item = getInnerText(t.tBodies[0].rows[i].cells[column]);
item = trim(item);
// Exclude cell values where commented out HTML exists
@@ -63,16 +79,24 @@
}
i++;
}
- if(item === '') return;
- var sortFunction;
+ if (item === '') {
+ return;
+ }
// Possible sortFunction scenarios
var sortCaseInsensitive = function (a, b) {
var aa = getInnerText(a.cells[that.col]).toLowerCase();
var bb = getInnerText(b.cells[that.col]).toLowerCase();
- if(aa === bb) return 0;
- if(aa < bb) return 1;
+
+ if(aa === bb) {
+ return 0;
+ }
+
+ if(aa < bb) {
+ return 1;
+ }
+
return -1;
};
var sortNumber = function (a, b) {
@@ -89,25 +113,26 @@
};
// Sort as number if a currency key exists or number
- if(item.match(/^-?$€Û¢´]\d/) || item.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)) {
+ if (item.match(/^-?\x24Û¢´]\d/) || item.match(/^-?(\d+[,\.]?)+(E[\-+][\d]+)?%?$/)) {
sortFunction = sortNumber;
- } else if(testDate(item)) {
+ } else if (testDate(item)) {
sortFunction = sortDate;
} else {
sortFunction = sortCaseInsensitive;
}
+
this.col = column;
var firstRow = [],
newRows = [],
k, j;
- for(k = 0; k < t.tBodies.length; k++) {
+ for (k = 0; k < t.tBodies.length; k++) {
for(i = 0; i < t.tBodies[k].rows[0].length; i++) {
firstRow[i] = t.tBodies[k].rows[0][i];
}
}
- for(k = 0; k < t.tBodies.length; k++) {
- if(!that.thead) {
+ for (k = 0; k < t.tBodies.length; k++) {
+ if (!that.thead) {
// skip the first row
for(j = 1; j < t.tBodies[k].rows.length; j++) {
newRows[j - 1] = t.tBodies[k].rows[j];
@@ -142,7 +167,9 @@
}
// Before we append should we reverse the new array or not?
- if(hasClass(header, 'sort-down')) newRows.reverse();
+ if(hasClass(header, 'sort-down')) {
+ newRows.reverse();
+ }
// append rows that already exist rather than creating new ones
for(i = 0; i < newRows.length; i++) {
@@ -153,8 +180,11 @@
}
}
},
+
refresh: function() {
- if (this.current !== undefined) this.sortTable(this.current, true);
+ if (this.current !== undefined) {
+ this.sortTable(this.current, true);
+ }
}
};
@@ -175,34 +205,44 @@
return new Date(date).getTime();
},
getParent = function (el, pTagName) {
- if(el === null) {
+ if (el === null) {
return null;
- } else if(el.nodeType === 1 && el.tagName.toLowerCase() === pTagName.toLowerCase()) {
+ } else if (el.nodeType === 1 && el.tagName.toLowerCase() === pTagName.toLowerCase()) {
return el;
} else {
return getParent(el.parentNode, pTagName);
}
},
getInnerText = function (el) {
var that = this;
- if(typeof el === 'string' || typeof el === 'undefined') return el;
- if(el.textContent) return el.textContent;
- if(el.innerText) return el.innerText;
- var str = '';
- var cs = el.childNodes;
- var l = cs.length;
- for(var i = 0; i < l; i++) {
- switch(cs[i].nodeType) {
- case 1:
- // ELEMENT_NODE
- str += that.getInnerText(cs[i]);
+
+ if (typeof el === 'string' || typeof el === 'undefined') {
+ return el;
+ }
+ if (el.textContent) {
+ return el.textContent;
+ }
+ if (el.innerText) {
+ return el.innerText;
+ }
+
+ var str = '',
+ cs = el.childNodes,
+ l = cs.length;
+
+ for (var i = 0; i < l; i++) {
+ switch (cs[i].nodeType) {
+ case 1:
+ // ELEMENT_NODE
+ str += that.getInnerText(cs[i]);
break;
- case 3:
- // TEXT_NODE
- str += cs[i].nodeValue;
+ case 3:
+ // TEXT_NODE
+ str += cs[i].nodeValue;
break;
}
}
+
return str;
},
compareNumber = function (a, b) {
@@ -235,4 +275,4 @@
};
window.Tablesort = Tablesort;
-})();
+})();
View
8 tablesort.min.js
@@ -1,4 +1,4 @@
-// tablesort.js
-// Version: 1.5.0
-// Author: tristen @fallsemo
-(function(){function a(a,b){a.tagName==="TABLE"?this.init(a,b||{}):console.error("Element must be a table")}a.prototype={init:function(a,b){var c=this,d;this.thead=!1,this.options=b,this.options.d=b.descending||!1,a.rows&&a.rows.length>0&&(a.tHead&&a.tHead.rows.length>0?(d=a.tHead.rows[a.tHead.rows.length-1],c.thead=!0):d=a.rows[0]);if(!d)return;for(var e=0;e<d.cells.length;e++){var f=d.cells[e];l(f,"no-sort")||(f.className+=" sort-header",m(f,"click",function(a){var b=g(f,"tr").getElementsByTagName("th");for(var d=0;d<b.length;d++)(l(b[d],"sort-up")||l(b[d],"sort-down"))&&b[d]!==this&&(b[d].className=b[d].className.replace(" sort-down","").replace(" sort-up",""));c.current=this,c.sortTable(this)}))}},sortTable:function(a,b){var c=this,d=a.cellIndex,m=g(a,"table");if(m.rows.length<=1)return;var n="",o=0;while(n===""&&o<m.tBodies[0].rows.length){n=h(m.tBodies[0].rows[o].cells[d]),n=j(n);if(n.substr(0,4)==="<!--"||n.length===0)n="";o++}if(n==="")return;var p,q=function(a,b){var d=h(a.cells[c.col]).toLowerCase(),e=h(b.cells[c.col]).toLowerCase();return d===e?0:d<e?1:-1},r=function(a,b){var d=h(a.cells[c.col]);d=k(d);var e=h(b.cells[c.col]);return e=k(e),i(e,d)},s=function(a,b){var d=h(a.cells[c.col]).toLowerCase(),e=h(b.cells[c.col]).toLowerCase();return f(e)-f(d)};n.match(/^-?[£$€Û¢´]\d/)||n.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)?p=r:e(n)?p=s:p=q,this.col=d;var t=[],u=[],v,w;for(v=0;v<m.tBodies.length;v++)for(o=0;o<m.tBodies[v].rows[0].length;o++)t[o]=m.tBodies[v].rows[0][o];for(v=0;v<m.tBodies.length;v++)if(!c.thead)for(w=1;w<m.tBodies[v].rows.length;w++)u[w-1]=m.tBodies[v].rows[w];else for(w=0;w<m.tBodies[v].rows.length;w++)u[w]=m.tBodies[v].rows[w];u.sort(p),b||(c.options.d?l(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"):l(a,"sort-down")?(a.className=a.className.replace(/ sort-down/,""),a.className+=" sort-up"):(a.className=a.className.replace(/ sort-up/,""),a.className+=" sort-down")),l(a,"sort-down")&&u.reverse();for(o=0;o<u.length;o++)l(u[o],"no-sort")||m.tBodies[0].appendChild(u[o])},refresh:function(){this.current!==undefined&&this.sortTable(this.current,!0)}};var b=/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,c=/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,d=/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i,e=function(a){return(a.search(b)!==-1||a.search(c)!==-1||a.search(d!==-1))!==-1},f=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()},g=function(a,b){return a===null?null:a.nodeType===1&&a.tagName.toLowerCase()===b.toLowerCase()?a:g(a.parentNode,b)},h=function(a){var b=this;if(typeof a=="string"||typeof a=="undefined")return a;if(a.textContent)return a.textContent;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},i=function(a,b){var c=parseFloat(a);a=isNaN(c)?0:c;var d=parseFloat(b);return b=isNaN(d)?0:d,a-b},j=function(a){return a.replace(/^\s+|\s+$/g,"")},k=function(a){return a.replace(/[^\-?0-9.]/g,"")},l=function(a,b){return(" "+a.className+" ").indexOf(" "+b+" ")>-1},m=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)};window.Tablesort=a})();
+/*! tablesort - v1.6.0 - 2012-11-07
+* http://tristen.ca/tablesort/demo
+* Copyright (c) 2012 ; Licensed MIT */
+(function(){function e(e,t){if(e.tagName!=="TABLE")throw new Error("Element must be a table");this.init(e,t||{})}e.prototype={init:function(e,t){var n=this,r;this.thead=!1,this.options=t,this.options.d=t.descending||!1,e.rows&&e.rows.length>0&&(e.tHead&&e.tHead.rows.length>0?(r=e.tHead.rows[e.tHead.rows.length-1],n.thead=!0):r=e.rows[0]);if(!r)return;var i=function(e){var t=o(u,"tr").getElementsByTagName("th");for(var r=0;r<t.length;r++)(c(t[r],"sort-up")||c(t[r],"sort-down"))&&t[r]!==this&&(t[r].className=t[r].className.replace(" sort-down","").replace(" sort-up",""));n.current=this,n.sortTable(this)};for(var s=0;s<r.cells.length;s++){var u=r.cells[s];c(u,"no-sort")||(u.className+=" sort-header",h(u,"click",i))}},sortTable:function(e,t){var n=this,r=e.cellIndex,h,p=o(e,"table"),d="",v=0;if(p.rows.length<=1)return;while(d===""&&v<p.tBodies[0].rows.length){d=u(p.tBodies[0].rows[v].cells[r]),d=f(d);if(d.substr(0,4)==="<!--"||d.length===0)d="";v++}if(d==="")return;var m=function(e,t){var r=u(e.cells[n.col]).toLowerCase(),i=u(t.cells[n.col]).toLowerCase();return r===i?0:r<i?1:-1},g=function(e,t){var r=u(e.cells[n.col]);r=l(r);var i=u(t.cells[n.col]);return i=l(i),a(i,r)},y=function(e,t){var r=u(e.cells[n.col]).toLowerCase(),i=u(t.cells[n.col]).toLowerCase();return s(i)-s(r)};d.match(/^-?[£\x24Û¢´]\d/)||d.match(/^-?(\d+[,\.]?)+(E[\-+][\d]+)?%?$/)?h=g:i(d)?h=y:h=m,this.col=r;var b=[],w=[],E,S;for(E=0;E<p.tBodies.length;E++)for(v=0;v<p.tBodies[E].rows[0].length;v++)b[v]=p.tBodies[E].rows[0][v];for(E=0;E<p.tBodies.length;E++)if(!n.thead)for(S=1;S<p.tBodies[E].rows.length;S++)w[S-1]=p.tBodies[E].rows[S];else for(S=0;S<p.tBodies[E].rows.length;S++)w[S]=p.tBodies[E].rows[S];w.sort(h),t||(n.options.d?c(e,"sort-up")?(e.className=e.className.replace(/ sort-up/,""),e.className+=" sort-down"):(e.className=e.className.replace(/ sort-down/,""),e.className+=" sort-up"):c(e,"sort-down")?(e.className=e.className.replace(/ sort-down/,""),e.className+=" sort-up"):(e.className=e.className.replace(/ sort-up/,""),e.className+=" sort-down")),c(e,"sort-down")&&w.reverse();for(v=0;v<w.length;v++)c(w[v],"no-sort")||p.tBodies[0].appendChild(w[v])},refresh:function(){this.current!==undefined&&this.sortTable(this.current,!0)}};var t=/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i,n=/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/,r=/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i,i=function(e){return(e.search(t)!==-1||e.search(n)!==-1||e.search(r!==-1))!==-1},s=function(e){return e=e.replace(/\-/g,"/"),e=e.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3"),(new Date(e)).getTime()},o=function(e,t){return e===null?null:e.nodeType===1&&e.tagName.toLowerCase()===t.toLowerCase()?e:o(e.parentNode,t)},u=function(e){var t=this;if(typeof e=="string"||typeof e=="undefined")return e;if(e.textContent)return e.textContent;if(e.innerText)return e.innerText;var n="",r=e.childNodes,i=r.length;for(var s=0;s<i;s++)switch(r[s].nodeType){case 1:n+=t.getInnerText(r[s]);break;case 3:n+=r[s].nodeValue}return n},a=function(e,t){var n=parseFloat(e);e=isNaN(n)?0:n;var r=parseFloat(t);return t=isNaN(r)?0:r,e-t},f=function(e){return e.replace(/^\s+|\s+$/g,"")},l=function(e){return e.replace(/[^\-?0-9.]/g,"")},c=function(e,t){return(" "+e.className+" ").indexOf(" "+t+" ")>-1},h=function(e,t,n){e.attachEvent?(e["e"+t+n]=n,e[t+n]=function(){e["e"+t+n](window.event)},e.attachEvent("on"+t,e[t+n])):e.addEventListener(t,n,!1)};window.Tablesort=e})();

0 comments on commit 9cd3407

Please sign in to comment.
Something went wrong with that request. Please try again.