mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-19 22:26:18 +00:00
![Jermolene](/assets/img/avatar_default.png)
Now `[!field:name[value]]` and `[!has[name]` will treat missing tiddlers as not having the specified field
70 lines
1.5 KiB
JavaScript
70 lines
1.5 KiB
JavaScript
/*\
|
|
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) {
|
|
var results = [],
|
|
fieldname = (operator.suffix || operator.operator || "title").toLowerCase();
|
|
if(operator.prefix === "!") {
|
|
if(operator.regexp) {
|
|
source(function(tiddler,title) {
|
|
if(tiddler) {
|
|
var text = tiddler.getFieldString(fieldname);
|
|
if(text !== null && !operator.regexp.exec(text)) {
|
|
results.push(title);
|
|
}
|
|
} else {
|
|
results.push(title);
|
|
}
|
|
});
|
|
} else {
|
|
source(function(tiddler,title) {
|
|
if(tiddler) {
|
|
var text = tiddler.getFieldString(fieldname);
|
|
if(text !== null && text !== operator.operand) {
|
|
results.push(title);
|
|
}
|
|
} else {
|
|
results.push(title);
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
if(operator.regexp) {
|
|
source(function(tiddler,title) {
|
|
if(tiddler) {
|
|
var text = tiddler.getFieldString(fieldname);
|
|
if(text !== null && !!operator.regexp.exec(text)) {
|
|
results.push(title);
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
source(function(tiddler,title) {
|
|
if(tiddler) {
|
|
var text = tiddler.getFieldString(fieldname);
|
|
if(text !== null && text === operator.operand) {
|
|
results.push(title);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
return results;
|
|
};
|
|
|
|
})();
|