kopia lustrzana https://github.com/miklobit/TiddlyWiki5
commit
5dea8ca758
|
@ -16,6 +16,30 @@ Filter operator for sorting
|
|||
Export our filter function
|
||||
*/
|
||||
exports.sort = function(source,operator,options) {
|
||||
var results = prepare_results(source);
|
||||
options.wiki.sortTiddlers(results,operator.operand,operator.prefix === "!",false,false);
|
||||
return results;
|
||||
};
|
||||
|
||||
exports.nsort = function(source,operator,options) {
|
||||
var results = prepare_results(source);
|
||||
options.wiki.sortTiddlers(results,operator.operand,operator.prefix === "!",false,true);
|
||||
return results;
|
||||
};
|
||||
|
||||
exports.sortcs = function(source,operator,options) {
|
||||
var results = prepare_results(source);
|
||||
options.wiki.sortTiddlers(results,operator.operand,operator.prefix === "!",true,false);
|
||||
return results;
|
||||
};
|
||||
|
||||
exports.nsortcs = function(source,operator,options) {
|
||||
var results = prepare_results(source);
|
||||
options.wiki.sortTiddlers(results,operator.operand,operator.prefix === "!",true,true);
|
||||
return results;
|
||||
};
|
||||
|
||||
var prepare_results = function (source) {
|
||||
var results;
|
||||
if($tw.utils.isArray(source)) {
|
||||
results = source;
|
||||
|
@ -25,8 +49,7 @@ exports.sort = function(source,operator,options) {
|
|||
results.push(title);
|
||||
});
|
||||
}
|
||||
options.wiki.sortTiddlers(results,operator.operand,operator.prefix === "!");
|
||||
return results;
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/*\
|
||||
title: $:/core/modules/filters/sortcs.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operator for case-sensitive sorting
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.sortcs = function(source,operator,options) {
|
||||
var results;
|
||||
if($tw.utils.isArray(source)) {
|
||||
results = source;
|
||||
} else {
|
||||
results = [];
|
||||
$tw.utils.each(source,function(element,title) {
|
||||
results.push(title);
|
||||
});
|
||||
}
|
||||
options.wiki.sortTiddlers(results,operator.operand,operator.prefix === "!",true);
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
|
@ -305,13 +305,14 @@ Sort an array of tiddler titles by a specified field
|
|||
isDescending: true if the sort should be descending
|
||||
isCaseSensitive: true if the sort should consider upper and lower case letters to be different
|
||||
*/
|
||||
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive) {
|
||||
exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,isNumeric) {
|
||||
var self = this;
|
||||
titles.sort(function(a,b) {
|
||||
if(sortField !== "title") {
|
||||
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();
|
||||
|
@ -320,6 +321,11 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive) {
|
|||
b = b.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
a-= 0;
|
||||
b-= 0;
|
||||
}
|
||||
if(a < b) {
|
||||
return isDescending ? +1 : -1;
|
||||
} else {
|
||||
|
|
|
@ -39,6 +39,8 @@ A filter string consists of one or more runs of filter operators that each look
|
|||
* ''has'': tests whether a tiddler has the field specified in the operand
|
||||
* ''sort'': sorts the tiddlers by the field specified in the operand
|
||||
* ''sortcs'': a case sensitive sort of the current tiddlers by the field specified in the operand
|
||||
* ''nsort'': sorts the tiddlers numerically by the field specified in the operand
|
||||
* ''nsortcs'': a case sensitive (for the non-numerical elements) numerical sort of the current tiddlers by the field specified in the operand
|
||||
* ''prefix'': tests whether a tiddlers title starts with the prefix specified in the operand
|
||||
* ''limit'': limits the number of subresults to the integer specified in the operand
|
||||
* ''tag'': tests whether a given tag is (`[tag[mytag]]`) or is not (`[!tag[mytag]]`) present on the tiddler
|
||||
|
|
Ładowanie…
Reference in New Issue