mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Remove eval(), fixing minifier issues
The eval() inside multisort() was causing minifier variable collision with a few minifiers. Since this eval isn't necessary it might as well be removed so the browser can also optimize the code path.
This commit is contained in:
parent
9b763d5baa
commit
2f506a34e5
@ -455,42 +455,34 @@
|
|||||||
sortTime, i, j, k, c, cache, lc, s, e, order, orgOrderCol;
|
sortTime, i, j, k, c, cache, lc, s, e, order, orgOrderCol;
|
||||||
if (tc.debug) { sortTime = new Date(); }
|
if (tc.debug) { sortTime = new Date(); }
|
||||||
for (k = 0; k < bl; k++) {
|
for (k = 0; k < bl; k++) {
|
||||||
dynamicExp = "sortWrapper = function(a,b) {";
|
|
||||||
cache = tc.cache[k];
|
cache = tc.cache[k];
|
||||||
lc = cache.normalized.length;
|
lc = cache.normalized.length;
|
||||||
|
cache.normalized.sort(function(a, b) {
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
c = sortList[i][0];
|
c = sortList[i][0];
|
||||||
order = sortList[i][1];
|
order = sortList[i][1];
|
||||||
// fallback to natural sort since it is more robust
|
// fallback to natural sort since it is more robust
|
||||||
s = /n/i.test(getCachedSortType(tc.parsers, c)) ? "Numeric" : "Text";
|
s = /n/i.test(getCachedSortType(tc.parsers, c)) ? "Numeric" : "Text";
|
||||||
s += order === 0 ? "" : "Desc";
|
s += order === 0 ? "" : "Desc";
|
||||||
e = "e" + i;
|
|
||||||
// get max column value (ignore sign)
|
// get max column value (ignore sign)
|
||||||
if (/Numeric/.test(s) && tc.strings[c]) {
|
if (/Numeric/.test(s) && tc.strings[c]) {
|
||||||
for (j = 0; j < lc; j++) {
|
for (j = 0; j < lc; j++) {
|
||||||
col = Math.abs(parseFloat(cache.normalized[j][c]));
|
col = Math.abs(parseFloat(cache.normalized[j][c]));
|
||||||
mx = Math.max( mx, isNaN(col) ? 0 : col );
|
mx = Math.max(mx, isNaN(col) ? 0 : col);
|
||||||
}
|
}
|
||||||
// sort strings in numerical columns
|
// sort strings in numerical columns
|
||||||
if (typeof(tc.string[tc.strings[c]]) === 'boolean') {
|
if (typeof (tc.string[tc.strings[c]]) === 'boolean') {
|
||||||
dir = (order === 0 ? 1 : -1) * (tc.string[tc.strings[c]] ? -1 : 1);
|
dir = (order === 0 ? 1 : -1) * (tc.string[tc.strings[c]] ? -1 : 1);
|
||||||
} else {
|
} else {
|
||||||
dir = (tc.strings[c]) ? tc.string[tc.strings[c]] || 0 : 0;
|
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 + "); ";
|
var sort = $.tablesorter["sort" + s](table, a[c], b[c], c, mx, dir);
|
||||||
dynamicExp += "if (" + e + ") { return " + e + "; } ";
|
if (sort) { return sort; }
|
||||||
dynamicExp += "else { ";
|
|
||||||
}
|
}
|
||||||
// if value is the same keep orignal order
|
|
||||||
orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0;
|
orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0;
|
||||||
dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];";
|
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
|
|
||||||
}
|
}
|
||||||
if (tc.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order + " time", sortTime); }
|
if (tc.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order + " time", sortTime); }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user