From bb42c0ab360760917ad5bde84f15350186a9471a Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 17 Apr 2014 20:15:52 +0100 Subject: [PATCH] Use localCompare for sorting strings So that accented characters get sorted correctly. Or at least as correctly as browsers allow. --- core/modules/wiki.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index dfa53d491..ed1455300 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -305,28 +305,18 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is a = self.getTiddler(a).fields[sortField] || ""; b = self.getTiddler(b).fields[sortField] || ""; } - if(!isNumeric || isNaN(a) || isNaN(b)) { - if(!isCaseSensitive) { - if(typeof a === "string") { - a = a.toLowerCase(); - } - if(typeof b === "string") { - b = b.toLowerCase(); - } - } - } - else { - a-= 0; - b-= 0; - } - if(a < b) { - return isDescending ? +1 : -1; + if(isNumeric) { + a = Number(a); + b = Number(b); + return isDescending ? b - a : a - b; } else { - if(a > b) { - return isDescending ? -1 : +1; - } else { - return 0; + a = String(a); + b = String(b); + if(!isCaseSensitive) { + a = a.toLowerCase(); + b = b.toLowerCase(); } + return isDescending ? b.localeCompare(a) : a.localeCompare(b); } }); };