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:
Nick Craver 2012-11-21 10:48:46 -05:00
parent 9b763d5baa
commit 2f506a34e5

View File

@ -455,42 +455,34 @@
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++) {
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
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);
} else {
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); }
}