1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Merge pull request #1413 from tobibeer/1410-is-numeric

fix isNumeric in sortTiddlers in wiki.js
This commit is contained in:
Jeremy Ruston 2015-01-26 21:00:26 +00:00
commit e87aea6e1f

View File

@ -316,6 +316,14 @@ Sort an array of tiddler titles by a specified field
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric) {
var self = this;
titles.sort(function(a,b) {
var x,y,
compareNumbers = function(x,y) {
var result =
isNaN(x) && !isNaN(y) ? (isDescending ? -1 : 1) :
!isNaN(x) && isNaN(y) ? (isDescending ? 1 : -1) :
(isDescending ? y - x : x - y);
return result;
};
if(sortField !== "title") {
var tiddlerA = self.getTiddler(a),
tiddlerB = self.getTiddler(b);
@ -330,10 +338,10 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
b = "";
}
}
if(isNumeric) {
a = Number(a);
b = Number(b);
return isDescending ? b - a : a - b;
x = Number(a);
y = Number(b);
if(isNumeric && (!isNaN(x) || !isNaN(y))) {
return compareNumbers(x,y);
} else if($tw.utils.isDate(a) && $tw.utils.isDate(b)) {
return isDescending ? b - a : a - b;
} else {