2013-05-25 16:26:22 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/filters/field.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: filteroperator
|
|
|
|
|
|
|
|
Filter operator for comparing fields for equality
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
Export our filter function
|
|
|
|
*/
|
|
|
|
exports.field = function(source,operator,options) {
|
2014-01-24 19:15:27 +00:00
|
|
|
var results = [],
|
|
|
|
fieldname = (operator.suffix || operator.operator).toLowerCase();
|
2013-05-25 16:26:22 +00:00
|
|
|
// Function to check an individual title
|
|
|
|
function checkTiddler(title) {
|
|
|
|
var tiddler = options.wiki.getTiddler(title);
|
|
|
|
if(tiddler) {
|
2014-01-12 22:37:11 +00:00
|
|
|
var match,
|
2014-01-24 19:15:27 +00:00
|
|
|
text = tiddler.getFieldString(fieldname);
|
2014-01-10 09:32:49 +00:00
|
|
|
if(operator.regexp) {
|
2014-01-24 19:15:27 +00:00
|
|
|
match = !!operator.regexp.exec(text);
|
|
|
|
} else {
|
2014-01-12 22:37:11 +00:00
|
|
|
match = text === operator.operand;
|
2014-01-10 09:32:49 +00:00
|
|
|
}
|
2013-05-25 16:26:22 +00:00
|
|
|
if(operator.prefix === "!") {
|
|
|
|
match = !match;
|
|
|
|
}
|
|
|
|
if(match) {
|
|
|
|
results.push(title);
|
|
|
|
}
|
|
|
|
}
|
2013-07-05 21:37:55 +00:00
|
|
|
}
|
2013-05-25 16:26:22 +00:00
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|