2022-05-06 14:01:17 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/filters/unknown.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: filteroperator
|
|
|
|
|
2022-05-11 13:52:25 +00:00
|
|
|
Filter operator for handling unknown filter operators.
|
|
|
|
|
|
|
|
Not intended to be used directly by end users, hence the square brackets around the name.
|
2022-05-06 14:01:17 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var fieldFilterOperatorFn = require("$:/core/modules/filters/field.js").field;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Export our filter function
|
|
|
|
*/
|
2022-05-11 13:52:25 +00:00
|
|
|
exports["[unknown]"] = function(source,operator,options) {
|
2022-05-23 15:40:21 +00:00
|
|
|
if(operator.operator.charAt(0) === ".") {
|
|
|
|
var customDefinition = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(operator.operator);
|
|
|
|
if(customDefinition && customDefinition.srcVariable && customDefinition.srcVariable.isFunctionDefinition) {
|
|
|
|
var variables = Object.create(null);
|
2022-05-23 19:18:54 +00:00
|
|
|
// Go through each of the defined parameters, and make a variable with the value of the corresponding operand
|
2022-05-23 15:40:21 +00:00
|
|
|
$tw.utils.each(customDefinition.srcVariable.params,function(param,index) {
|
2022-05-30 17:04:37 +00:00
|
|
|
var value = operator.operands[index];
|
|
|
|
variables[param.name] = value === undefined ? param["default"] || "" : value;
|
2022-05-23 15:40:21 +00:00
|
|
|
});
|
2022-05-23 19:18:54 +00:00
|
|
|
var list = options.wiki.filterTiddlers(customDefinition.srcVariable.value,options.widget.makeFakeWidgetWithVariables(variables),source);
|
2022-05-23 15:40:21 +00:00
|
|
|
if(operator.prefix === "!") {
|
|
|
|
var results = [];
|
|
|
|
source(function(tiddler,title) {
|
|
|
|
if(list.indexOf(title) === -1) {
|
|
|
|
results.push(title);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return results;
|
2022-05-09 17:00:09 +00:00
|
|
|
} else {
|
2022-05-23 15:40:21 +00:00
|
|
|
return list;
|
|
|
|
}
|
2022-05-06 14:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-23 15:40:21 +00:00
|
|
|
return fieldFilterOperatorFn(source,operator,options);
|
2022-05-06 14:01:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|