mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-19 22:26:18 +00:00
![Jermolene](/assets/img/avatar_default.png)
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...
50 lines
1.1 KiB
JavaScript
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;
|
|
};
|
|
|
|
})();
|