mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-04-27 07:40:52 -07:00
Replace multiple isDescending with reverse
This commit is contained in:
parent
689ad53acc
commit
793177b8bc
1 changed files with 20 additions and 29 deletions
|
|
@ -375,25 +375,13 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
|
|||
if(sortField === "title") {
|
||||
if(!isNumeric && !isAlphaNumeric) {
|
||||
if(isCaseSensitive) {
|
||||
if(isDescending) {
|
||||
titles.sort(function(a,b) {
|
||||
return b.localeCompare(a, locale);
|
||||
});
|
||||
} else {
|
||||
titles.sort(function(a,b) {
|
||||
return a.localeCompare(b, locale);
|
||||
});
|
||||
}
|
||||
titles.sort(function(a,b) {
|
||||
return a.localeCompare(b, locale);
|
||||
});
|
||||
} else {
|
||||
if(isDescending) {
|
||||
titles.sort(function(a,b) {
|
||||
return b.toLowerCase().localeCompare(a.toLowerCase(), locale);
|
||||
});
|
||||
} else {
|
||||
titles.sort(function(a,b) {
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase(), locale);
|
||||
});
|
||||
}
|
||||
titles.sort(function(a,b) {
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase(), locale);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
titles.sort(function(a,b) {
|
||||
|
|
@ -405,24 +393,24 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
|
|||
if(isNaN(y)) {
|
||||
// If neither value is a number then fall through to a textual comparison
|
||||
} else {
|
||||
return isDescending ? -1 : 1;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if(isNaN(y)) {
|
||||
return isDescending ? 1 : -1;
|
||||
return -1;
|
||||
} else {
|
||||
return isDescending ? y - x : x - y;
|
||||
return x - y;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isAlphaNumeric) {
|
||||
return isDescending ? b.localeCompare(a,locale,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
|
||||
return a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
|
||||
}
|
||||
if(!isCaseSensitive) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
}
|
||||
return isDescending ? b.localeCompare(a, locale) : a.localeCompare(b, locale);
|
||||
return a.localeCompare(b, locale);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
|
@ -449,31 +437,34 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
|
|||
if(isNaN(y)) {
|
||||
// If neither value is a number then fall through to a textual comparison
|
||||
} else {
|
||||
return isDescending ? -1 : 1;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if(isNaN(y)) {
|
||||
return isDescending ? 1 : -1;
|
||||
return -1;
|
||||
} else {
|
||||
return isDescending ? y - x : x - y;
|
||||
return x - y;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Object.prototype.toString.call(a) === "[object Date]" && Object.prototype.toString.call(b) === "[object Date]") {
|
||||
return isDescending ? b - a : a - b;
|
||||
return a - b;
|
||||
}
|
||||
a = String(a);
|
||||
b = String(b);
|
||||
if(isAlphaNumeric) {
|
||||
return isDescending ? b.localeCompare(a,locale,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
|
||||
return a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
|
||||
}
|
||||
if(!isCaseSensitive) {
|
||||
a = a.toLowerCase();
|
||||
b = b.toLowerCase();
|
||||
}
|
||||
return isDescending ? b.localeCompare(a, locale) : a.localeCompare(b, locale);
|
||||
return a.localeCompare(b, locale);
|
||||
});
|
||||
}
|
||||
if(isDescending) {
|
||||
titles.reverse();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue