mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-12 02:10:27 +00:00
Added limit filter operator
This commit is contained in:
parent
d99b70e0b2
commit
cfcb255c23
@ -31,6 +31,8 @@ The operators look like `[operator[operand]]`, where `operator` is one of:
|
|||||||
* ''title'': selects the tiddler with the title given in the operand
|
* ''title'': selects the tiddler with the title given in the operand
|
||||||
* ''is'': tests whether a tiddler is a member of the system defined set named in the operand (see below)
|
* ''is'': tests whether a tiddler is a member of the system defined set named in the operand (see below)
|
||||||
* ''has'': tests whether a tiddler has a specified field
|
* ''has'': tests whether a tiddler has a specified field
|
||||||
|
* ''sort'': sorts the tiddlers by a given field
|
||||||
|
* ''limit'': limits the number of subresults
|
||||||
* ''tag'': tests whether a given tag is (`[tag[mytag]]`) or is not (`[!tag[mytag]]`) present on the tiddler
|
* ''tag'': tests whether a given tag is (`[tag[mytag]]`) or is not (`[!tag[mytag]]`) present on the tiddler
|
||||||
* ''<field>'': tests whether a tiddler field has a specified value (`[modifier[Jeremy]]`) or not (`[!modifier[Jeremy]]`)
|
* ''<field>'': tests whether a tiddler field has a specified value (`[modifier[Jeremy]]`) or not (`[!modifier[Jeremy]]`)
|
||||||
|
|
||||||
@ -192,6 +194,16 @@ exports.operators = {
|
|||||||
return "this.sortTiddlers(subResults,\"" + $tw.utils.stringify(operator.operand) + "\"," + desc + ");";
|
return "this.sortTiddlers(subResults,\"" + $tw.utils.stringify(operator.operand) + "\"," + desc + ");";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"limit": {
|
||||||
|
selector: function(operator) {
|
||||||
|
throw "Cannot use limit operator at the start of a filter operation";
|
||||||
|
},
|
||||||
|
filter: function(operator) {
|
||||||
|
var limit = parseInt(operator.operand,10),
|
||||||
|
base = operator.prefix === "!" ? 0 : limit;
|
||||||
|
return "if(subResults.length > " + limit + ") {subResults.splice(" + base + ",subResults.length-" + limit + ");}";
|
||||||
|
}
|
||||||
|
},
|
||||||
"field": {
|
"field": {
|
||||||
selector: function(operator) {
|
selector: function(operator) {
|
||||||
var op = operator.prefix === "!" ? "!" : "=";
|
var op = operator.prefix === "!" ? "!" : "=";
|
||||||
|
Loading…
Reference in New Issue
Block a user