1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-03 18:53:28 +00:00
TiddlyWiki5/core/modules/filters/list.js
Jermolene 0b3efe179e Extend list filter operator to take a text reference
Instead of just a title. Means that we can apply the list operator to
fields other than the list field.
2014-01-25 18:14:30 +00:00

49 lines
1008 B
JavaScript

/*\
title: $:/core/modules/filters/list.js
type: application/javascript
module-type: filteroperator
Filter operator returning the tiddlers whose title is listed in the operand tiddler
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.list = function(source,operator,options) {
var results = [],
tr = $tw.utils.parseTextReference(operator.operand),
list = $tw.wiki.getTiddlerList(tr.title,tr.field,tr.index);
function checkTiddler(title) {
var match = list.indexOf(title) !== -1;
if(operator.prefix === "!") {
match = !match;
}
if(match) {
results.push(title);
}
}
// Iterate through the source tiddlers
if($tw.utils.isArray(source)) {
$tw.utils.each(source,function(title) {
checkTiddler(title);
});
} else {
if(operator.prefix !== "!") {
results = list;
} else {
$tw.utils.each(source,function(element,title) {
checkTiddler(title);
});
}
}
return results;
};
})();