mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-18 18:29:42 +00:00
ef3e44eb48
based on #1422, improves readability of the filter expression tests passed
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
/*\
|
|
title: $:/core/modules/filters/each.js
|
|
type: application/javascript
|
|
module-type: filteroperator
|
|
|
|
Filter operator that selects one tiddler for each unique value of the specified field.
|
|
With suffix "list", selects all tiddlers that are values in a specified list field.
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Export our filter function
|
|
*/
|
|
exports.each = function(source,operator,options) {
|
|
var results =[] ,
|
|
value,values = {},
|
|
field = operator.operand || "title";
|
|
if(operator.suffix !== "list-item") {
|
|
source(function(tiddler,title) {
|
|
if(tiddler) {
|
|
value = (field === "title") ? title : tiddler.getFieldString(field);
|
|
if(!$tw.utils.hop(values,value)) {
|
|
values[value] = true;
|
|
results.push(title);
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
source(function(tiddler,title) {
|
|
if(tiddler) {
|
|
$tw.utils.each(
|
|
options.wiki.getTiddlerList(title,field),
|
|
function(value) {
|
|
if(!$tw.utils.hop(values,value)) {
|
|
values[value] = true;
|
|
results.push(value);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
});
|
|
}
|
|
return results;
|
|
};
|
|
|
|
})();
|