1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-03 18:53:28 +00:00
TiddlyWiki5/core/modules/filters/list.js
Tobias Beer 4991c4d6dc just fixes list filter, no further refactoring
previously did not correctly handle / match the source but only output
the list as is

replaces https://github.com/Jermolene/TiddlyWiki5/pull/1419
2015-02-11 12:01:57 +01:00

38 lines
890 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),
currTiddlerTitle = options.widget && options.widget.getVariable("currentTiddler"),
list = options.wiki.getTiddlerList(tr.title || currTiddlerTitle,tr.field,tr.index);
if(operator.prefix === "!") {
source(function(tiddler,title) {
if(list.indexOf(title) === -1) {
results.push(title);
}
});
} else {
source(function(tiddler,title) {
if(list.indexOf(title) > -1) {
results.push(title);
}
});
}
return results;
};
})();