From f0b6790ae13de1e53548bc9ed42430f70b480043 Mon Sep 17 00:00:00 2001 From: David Johnston Date: Sun, 22 Sep 2013 09:58:18 +0100 Subject: [PATCH] Previous in list filter. --- core/modules/filters/previous.js | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 core/modules/filters/previous.js diff --git a/core/modules/filters/previous.js b/core/modules/filters/previous.js new file mode 100644 index 000000000..cc536b8af --- /dev/null +++ b/core/modules/filters/previous.js @@ -0,0 +1,43 @@ +/*\ +title: $:/core/modules/filters/previous.js +type: application/javascript +module-type: filteroperator + +Filter operator returning the tiddler whose title occurs immediately prior in the list supplied in the operand tiddler + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.previous = function(source,operator,options) { + var results = [], + list = options.wiki.getTiddlerList(operator.operand); + + function checkTiddler(title) { + var match = list.indexOf(title); + // decrement match and then test if result is in range + match--; + if( match >= 0 ) { + results.push(list[match]); + } + } + // 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; +}; + +})();