mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-15 16:59:43 +00:00
46 lines
905 B
JavaScript
46 lines
905 B
JavaScript
|
/*\
|
||
|
title: $:/core/modules/filters/contains.js
|
||
|
type: application/javascript
|
||
|
module-type: filteroperator
|
||
|
|
||
|
Filter operator for finding values in array fields
|
||
|
|
||
|
\*/
|
||
|
(function(){
|
||
|
|
||
|
/*jslint node: true, browser: true */
|
||
|
/*global $tw: false */
|
||
|
"use strict";
|
||
|
|
||
|
/*
|
||
|
Export our filter function
|
||
|
*/
|
||
|
exports.contains = function(source,operator,options) {
|
||
|
var results = [],
|
||
|
fieldname = (operator.suffix || "list").toLowerCase();
|
||
|
if(operator.prefix === "!") {
|
||
|
source(function(tiddler,title) {
|
||
|
if(tiddler) {
|
||
|
var list = tiddler.getFieldList(fieldname);
|
||
|
if(list.indexOf(operator.operand) === -1) {
|
||
|
results.push(title);
|
||
|
}
|
||
|
} else {
|
||
|
results.push(title);
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
source(function(tiddler,title) {
|
||
|
if(tiddler) {
|
||
|
var list = tiddler.getFieldList(fieldname);
|
||
|
if(list.indexOf(operator.operand) !== -1) {
|
||
|
results.push(title);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
return results;
|
||
|
};
|
||
|
|
||
|
})();
|