1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-18 18:29:42 +00:00
TiddlyWiki5/core/modules/filters/is.js
Matt Lauber 5ea6c9a273 Modify the is operator to allow multiple types to be specified. (#2982)
* Modify the is operator to allow multiple types to be specified.

* Fixed indentation.

* Fixed indentation.

* Rewritten to maintain input order when multiple filters provided.

* Updated documentation.

* Update is.tid
2018-04-12 13:21:49 +01:00

67 lines
1.4 KiB
JavaScript

/*\
title: $:/core/modules/filters/is.js
type: application/javascript
module-type: filteroperator
Filter operator for checking tiddler properties
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var isFilterOperators;
function getIsFilterOperators() {
if(!isFilterOperators) {
isFilterOperators = {};
$tw.modules.applyMethods("isfilteroperator",isFilterOperators);
}
return isFilterOperators;
}
/*
Export our filter function
*/
exports.is = function(source,operator,options) {
if( !operator.operand) {
// Return all tiddlers if the operand is missing
var results = [];
source(function(tiddler,title) {
results.push(title);
});
return results;
}
// Get our isfilteroperators
var isFilterOperators = getIsFilterOperators(),
subops = operator.operand.split("+"),
filteredResults = {},
results = [];
for (var t=0; t<subops.length; t++) {
var subop = isFilterOperators[subops[t]];
if(subop) {
filteredResults[subops[t]] = subop(source,operator.prefix,options);
} else {
return [$tw.language.getString("Error/IsFilterOperator")];
}
}
source(function(tiddler,title) {
for (var t=0; t<subops.length; t++) {
if (filteredResults[subops[t]].indexOf(title) != -1){
results.push(title);
break;
}
}
});
return results;
};
})();