1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-29 08:43:14 +00:00
TiddlyWiki5/core/modules/filters/tag.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

/*\
title: $:/core/modules/filters/tag.js
type: application/javascript
module-type: filteroperator
Filter operator for checking for the presence of a tag
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.tag = function(source,operator,options) {
var results = [];
2016-11-28 13:42:30 +00:00
if((operator.suffix || "").toLowerCase() === "strict" && !operator.operand) {
// New semantics:
// Always return copy of input if operator.operand is missing
source(function(tiddler,title) {
2016-11-28 13:42:30 +00:00
results.push(title);
});
} else {
2016-11-28 13:42:30 +00:00
// Old semantics:
var tiddlers = options.wiki.getTiddlersWithTag(operator.operand);
2016-11-28 13:42:30 +00:00
if(operator.prefix === "!") {
// Returns a copy of the input if operator.operand is missing
source(function(tiddler,title) {
if(tiddlers.indexOf(title) === -1) {
2016-11-28 13:42:30 +00:00
results.push(title);
}
});
} else {
// Returns empty results if operator.operand is missing
source(function(tiddler,title) {
if(tiddlers.indexOf(title) !== -1) {
2016-11-28 13:42:30 +00:00
results.push(title);
}
});
results = options.wiki.sortByList(results,operator.operand);
}
}
return results;
};
})();