1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-04 19:23:29 +00:00
TiddlyWiki5/core/modules/filters/fields.js
Mario Pietsch de5b0062b5
Add new parameters to fields-widget and fields-operator. (#4433)
* add a new-line before the log text to increase readability of the test output

* make eslint, jslint happy

* extend fields-widget with include/exclude/sort/reverse and fields-filter with include and exclude params plus DOCS

* remove new-line

* remove eslint settings

* restore old eslint settings

* remove typo
2020-04-15 12:36:48 +01:00

46 lines
1.1 KiB
JavaScript

/*\
title: $:/core/modules/filters/fields.js
type: application/javascript
module-type: filteroperator
Filter operator for returning the names of the fields on the selected tiddlers
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.fields = function(source,operator,options) {
var results = [],
fieldName,
suffixes = (operator.suffixes || [])[0] || [],
operand = $tw.utils.parseStringArray(operator.operand);
source(function(tiddler,title) {
if(tiddler) {
if(suffixes.indexOf("include") !== -1) {
for(fieldName in tiddler.fields) {
(operand.indexOf(fieldName) !== -1) ? $tw.utils.pushTop(results,fieldName) : "";
}
} else if (suffixes.indexOf("exclude") !== -1) {
for(fieldName in tiddler.fields) {
(operand.indexOf(fieldName) !== -1) ? "" : $tw.utils.pushTop(results,fieldName);
}
} // else if
else {
for(fieldName in tiddler.fields) {
$tw.utils.pushTop(results,fieldName);
}
} // else
} // if (tiddler)
});
return results;
};
})();