mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Previous in list filter.
This commit is contained in:
parent
b72afda7a2
commit
f0b6790ae1
43
core/modules/filters/previous.js
Normal file
43
core/modules/filters/previous.js
Normal file
@ -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;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user