mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-19 02:39:42 +00:00
cc7b276787
This implementation was not useful.
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
/*\
|
|
title: $:/core/modules/filters/function.js
|
|
type: application/javascript
|
|
module-type: filteroperator
|
|
|
|
Filter operator returning those input titles that are returned from a function
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Export our filter function
|
|
*/
|
|
exports.function = function(source,operator,options) {
|
|
var functionName = operator.operands[0],
|
|
customDefinition = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(functionName);
|
|
if(customDefinition && customDefinition.srcVariable && customDefinition.srcVariable.isFunctionDefinition) {
|
|
var variables = Object.create(null);
|
|
// Go through each of the defined parameters, and make a variable with the value of the corresponding operand
|
|
$tw.utils.each(customDefinition.srcVariable.params,function(param,index) {
|
|
var value = operator.operands[1 + index]; // Skip over the first operand that gives the function name
|
|
variables[param.name] = value === undefined ? param["default"] || "" : value;
|
|
});
|
|
return options.wiki.filterTiddlers(customDefinition.srcVariable.value,options.widget.makeFakeWidgetWithVariables(variables),source);
|
|
}
|
|
// Return the input list if the function wasn't found
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push(title);
|
|
});
|
|
return results;
|
|
};
|
|
|
|
})();
|