mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-06-25 23:03:15 +00:00
Merge pull request #1413 from tobibeer/1410-is-numeric
fix isNumeric in sortTiddlers in wiki.js
This commit is contained in:
commit
e87aea6e1f
|
@ -316,6 +316,14 @@ Sort an array of tiddler titles by a specified field
|
||||||
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric) {
|
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric) {
|
||||||
var self = this;
|
var self = this;
|
||||||
titles.sort(function(a,b) {
|
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") {
|
if(sortField !== "title") {
|
||||||
var tiddlerA = self.getTiddler(a),
|
var tiddlerA = self.getTiddler(a),
|
||||||
tiddlerB = self.getTiddler(b);
|
tiddlerB = self.getTiddler(b);
|
||||||
|
@ -330,10 +338,10 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
|
||||||
b = "";
|
b = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isNumeric) {
|
x = Number(a);
|
||||||
a = Number(a);
|
y = Number(b);
|
||||||
b = Number(b);
|
if(isNumeric && (!isNaN(x) || !isNaN(y))) {
|
||||||
return isDescending ? b - a : a - b;
|
return compareNumbers(x,y);
|
||||||
} else if($tw.utils.isDate(a) && $tw.utils.isDate(b)) {
|
} else if($tw.utils.isDate(a) && $tw.utils.isDate(b)) {
|
||||||
return isDescending ? b - a : a - b;
|
return isDescending ? b - a : a - b;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user