diff --git a/core/modules/filters/listed.js b/core/modules/filters/listed.js new file mode 100644 index 000000000..07ad564d1 --- /dev/null +++ b/core/modules/filters/listed.js @@ -0,0 +1,37 @@ +/*\ +title: $:/core/modules/filters/listed.js +type: application/javascript +module-type: filteroperator + +Filter operator returning all tiddlers that have the selected tiddlers in a list + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.listed = function(source,operator,options) { + var results = []; + // Function to check an individual title + function checkTiddler(title) { + $tw.utils.pushTop(results,options.wiki.findListingsOfTiddler(title)); + } + // Iterate through the source tiddlers + if($tw.utils.isArray(source)) { + $tw.utils.each(source,function(title) { + checkTiddler(title); + }); + } else { + $tw.utils.each(source,function(element,title) { + checkTiddler(title); + }); + } + return results; +}; + +})(); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 1289b7507..69a29408d 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -415,13 +415,28 @@ exports.getTiddlersWithTag = function(tag) { var titles = []; for(var title in this.tiddlers) { var tiddler = this.tiddlers[title]; - if(tiddler.fields.tags && tiddler.fields.tags.indexOf(tag) !== -1) { + if($tw.utils.isArray(tiddler.fields.tags) && tiddler.fields.tags.indexOf(tag) !== -1) { titles.push(title); } } return this.sortByList(titles,tag); }; +/* +Lookup a given tiddler and return a list of all the tiddlers that include it in their list +*/ +exports.findListingsOfTiddler = function(targetTitle) { + // Get the list associated with the tag + var titles = []; + for(var title in this.tiddlers) { + var tiddler = this.tiddlers[title]; + if($tw.utils.isArray(tiddler.fields.list) && tiddler.fields.list.indexOf(targetTitle) !== -1) { + titles.push(title); + } + } + return titles; +}; + /* Sorts an array of tiddler titles according to an ordered list */