mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Merge pull request #177 from NickCraver/master
Removing eval() for performance, usage was also causing variable collision in some minifiers
This commit is contained in:
commit
57d892ca72
@ -455,16 +455,15 @@
|
||||
sortTime, i, j, k, c, cache, lc, s, e, order, orgOrderCol;
|
||||
if (tc.debug) { sortTime = new Date(); }
|
||||
for (k = 0; k < bl; k++) {
|
||||
dynamicExp = "sortWrapper = function(a,b) {";
|
||||
cache = tc.cache[k];
|
||||
lc = cache.normalized.length;
|
||||
cache.normalized.sort(function(a, b) {
|
||||
for (i = 0; i < l; i++) {
|
||||
c = sortList[i][0];
|
||||
order = sortList[i][1];
|
||||
// fallback to natural sort since it is more robust
|
||||
s = /n/i.test(getCachedSortType(tc.parsers, c)) ? "Numeric" : "Text";
|
||||
s += order === 0 ? "" : "Desc";
|
||||
e = "e" + i;
|
||||
// get max column value (ignore sign)
|
||||
if (/Numeric/.test(s) && tc.strings[c]) {
|
||||
for (j = 0; j < lc; j++) {
|
||||
@ -478,19 +477,12 @@
|
||||
dir = (tc.strings[c]) ? tc.string[tc.strings[c]] || 0 : 0;
|
||||
}
|
||||
}
|
||||
dynamicExp += "var " + e + " = $.tablesorter.sort" + s + "(table,a[" + c + "],b[" + c + "]," + c + "," + mx + "," + dir + "); ";
|
||||
dynamicExp += "if (" + e + ") { return " + e + "; } ";
|
||||
dynamicExp += "else { ";
|
||||
var sort = $.tablesorter["sort" + s](table, a[c], b[c], c, mx, dir);
|
||||
if (sort) { return sort; }
|
||||
}
|
||||
// if value is the same keep orignal order
|
||||
orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0;
|
||||
dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];";
|
||||
for (i=0; i < l; i++) {
|
||||
dynamicExp += "}; ";
|
||||
}
|
||||
dynamicExp += "return 0; ";
|
||||
dynamicExp += "}; ";
|
||||
cache.normalized.sort(eval(dynamicExp)); // sort using eval expression
|
||||
return a[orgOrderCol] - b[orgOrderCol];
|
||||
});
|
||||
}
|
||||
if (tc.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order + " time", sortTime); }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user