1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-08 04:54:23 +00:00
TiddlyWiki5/core/modules/filters/tag.js
Jermolene e4b10d42f9 Optimise the tag filter
Spending a bit more time with Chrome dev tools, and further to 254e1ca, this optimisation reduces the rendering time for the sample TOC from 1.9s to about 0.9s...
2017-12-21 16:13:47 +00:00

50 lines
1.1 KiB
JavaScript

/*\
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 = [];
if((operator.suffix || "").toLowerCase() === "strict" && !operator.operand) {
// New semantics:
// Always return copy of input if operator.operand is missing
source(function(tiddler,title) {
results.push(title);
});
} else {
// Old semantics:
var tiddlers = options.wiki.getTiddlersWithTag(operator.operand);
if(operator.prefix === "!") {
// Returns a copy of the input if operator.operand is missing
source(function(tiddler,title) {
if(tiddlers.indexOf(title) === -1) {
results.push(title);
}
});
} else {
// Returns empty results if operator.operand is missing
source(function(tiddler,title) {
if(tiddlers.indexOf(title) !== -1) {
results.push(title);
}
});
results = options.wiki.sortByList(results,operator.operand);
}
}
return results;
};
})();