Use localCompare for sorting strings

So that accented characters get sorted correctly. Or at least as
correctly as browsers allow.
print-window-tiddler
Jermolene 2014-04-17 20:15:52 +01:00
rodzic 95d291daac
commit bb42c0ab36
1 zmienionych plików z 10 dodań i 20 usunięć

Wyświetl plik

@ -305,28 +305,18 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
a = self.getTiddler(a).fields[sortField] || ""; a = self.getTiddler(a).fields[sortField] || "";
b = self.getTiddler(b).fields[sortField] || ""; b = self.getTiddler(b).fields[sortField] || "";
} }
if(!isNumeric || isNaN(a) || isNaN(b)) { if(isNumeric) {
if(!isCaseSensitive) { a = Number(a);
if(typeof a === "string") { b = Number(b);
a = a.toLowerCase(); return isDescending ? b - a : a - b;
}
if(typeof b === "string") {
b = b.toLowerCase();
}
}
}
else {
a-= 0;
b-= 0;
}
if(a < b) {
return isDescending ? +1 : -1;
} else { } else {
if(a > b) { a = String(a);
return isDescending ? -1 : +1; b = String(b);
} else { if(!isCaseSensitive) {
return 0; a = a.toLowerCase();
b = b.toLowerCase();
} }
return isDescending ? b.localeCompare(a) : a.localeCompare(b);
} }
}); });
}; };