mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-17 17:59:45 +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;
|
|
};
|
|
|
|
})();
|