mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-18 10:19:44 +00:00
cc576b052e
Fixes #930
39 lines
753 B
JavaScript
39 lines
753 B
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
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Export our filter function
|
|
*/
|
|
exports.each = function(source,operator,options) {
|
|
var results = [],
|
|
values = {};
|
|
source(function(tiddler,title) {
|
|
if(tiddler) {
|
|
var value;
|
|
if((operator.operand === "") || (operator.operand === "title")) {
|
|
value = title;
|
|
} else {
|
|
value = tiddler.getFieldString(operator.operand);
|
|
}
|
|
if(!$tw.utils.hop(values,value)) {
|
|
values[value] = true;
|
|
results.push(title);
|
|
}
|
|
}
|
|
});
|
|
return results;
|
|
};
|
|
|
|
})();
|