mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-28 02:50:27 +00:00
Add :reduce filter run prefix (#5196)
This commit is contained in:
parent
8ffe138942
commit
046746ba20
49
core/modules/filterrunprefixes/reduce.js
Normal file
49
core/modules/filterrunprefixes/reduce.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*\
|
||||
title: $:/core/modules/filterrunprefixes/reduce.js
|
||||
type: application/javascript
|
||||
module-type: filterrunprefix
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter prefix function
|
||||
*/
|
||||
exports.reduce = function(operationSubFunction) {
|
||||
return function(results,source,widget) {
|
||||
if(results.length > 0) {
|
||||
var accumulator = "";
|
||||
for(var index=0; index<results.length; index++) {
|
||||
var title = results[index],
|
||||
list = operationSubFunction($tw.wiki.makeTiddlerIterator([title]),{
|
||||
getVariable: function(name) {
|
||||
switch(name) {
|
||||
case "currentTiddler":
|
||||
return "" + title;
|
||||
case "accumulator":
|
||||
return "" + accumulator;
|
||||
case "index":
|
||||
return "" + index;
|
||||
case "revIndex":
|
||||
return "" + (results.length - 1 - index);
|
||||
case "length":
|
||||
return "" + results.length;
|
||||
default:
|
||||
return widget.getVariable(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
if(list.length > 0) {
|
||||
accumulator = "" + list[0];
|
||||
}
|
||||
}
|
||||
results.splice(0,results.length);
|
||||
results.push(accumulator);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user