1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-05 19:53:17 +00:00
TiddlyWiki5/core/modules/filters/eachday.js
Jeremy Ruston cf75b209ba Add eachday and sameday filter operators
These operators will enable us to group the recent changes list by day
2013-05-27 17:59:33 +01:00

43 lines
997 B
JavaScript

/*\
title: $:/core/modules/filters/eachday.js
type: application/javascript
module-type: filteroperator
Filter operator that selects one tiddler for each unique day covered by the specified date field
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.eachday = function(source,operator,options) {
// Convert the source to an array if necessary
if(!$tw.utils.isArray(source)) {
var copy = [];
$tw.utils.each(source,function(element,title) {
copy.push(title);
});
source = copy;
}
// Collect up the first tiddler with each unique day value of the specified field
var results = [],values = {};
$tw.utils.each(source,function(title) {
var tiddler = options.wiki.getTiddler(title);
if(tiddler) {
var value = tiddler.getFieldString(operator.operand).substr(0,8);
if(!$tw.utils.hop(values,value)) {
values[value] = true;
results.push(title);
}
}
});
return results;
};
})();