mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-20 04:50:03 +00:00
added $tw.utils.pushOnce
retained check for basic each nonetheless tests pass
This commit is contained in:
parent
4788725ccf
commit
d0a24bd9f0
@ -84,6 +84,15 @@ $tw.utils.each = function(object,callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Pushes a value to an array only when not yet contained.
|
||||||
|
*/
|
||||||
|
$tw.utils.pushOnce = function(array,value) {
|
||||||
|
if(0 > array.indexOf(value)){
|
||||||
|
array.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Helper for making DOM elements
|
Helper for making DOM elements
|
||||||
tag: tag name
|
tag: tag name
|
||||||
|
@ -17,19 +17,17 @@ With suffix "list", selects all tiddlers that are values in a specified list fie
|
|||||||
Export our filter function
|
Export our filter function
|
||||||
*/
|
*/
|
||||||
exports.each = function(source,operator,options) {
|
exports.each = function(source,operator,options) {
|
||||||
var results = [],
|
var results =[] ,
|
||||||
values = {},
|
value,values = {},
|
||||||
field = operator.operand || "title",
|
field = operator.operand || "title";
|
||||||
add = function(val,title) {
|
|
||||||
if(!$tw.utils.hop(values,val)) {
|
|
||||||
values[val] = true;
|
|
||||||
results.push(title);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if("list" !== operator.suffix) {
|
if("list" !== operator.suffix) {
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
add("title" === field ? title : tiddler.getFieldString(field),title);
|
value = "title" === field ? title : tiddler.getFieldString(field);
|
||||||
|
if(!$tw.utils.hop(values,value)) {
|
||||||
|
values[value] = true;
|
||||||
|
results.push(title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -38,7 +36,7 @@ exports.each = function(source,operator,options) {
|
|||||||
$tw.utils.each(
|
$tw.utils.each(
|
||||||
options.wiki.getTiddlerList(title,field),
|
options.wiki.getTiddlerList(title,field),
|
||||||
function(value) {
|
function(value) {
|
||||||
add(value,value);
|
$tw.utils.pushOnce(results,value);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user