implement hyperjson filtering

pull/1/head
ansuz 9 years ago
parent e51635c4bb
commit bac0e0ff88

@ -47,7 +47,7 @@ define([], function () {
return x; return x;
}; };
var DOM2HyperJSON = function(el, predicate){ var DOM2HyperJSON = function(el, predicate, filter){
if(!el.tagName && el.nodeType === Node.TEXT_NODE){ if(!el.tagName && el.nodeType === Node.TEXT_NODE){
return el.textContent; return el.textContent;
} }
@ -111,12 +111,16 @@ define([], function () {
i = 0; i = 0;
for(; i < el.childNodes.length; i++){ for(; i < el.childNodes.length; i++){
children.push(DOM2HyperJSON(el.childNodes[i], predicate)); children.push(DOM2HyperJSON(el.childNodes[i], predicate, filter));
} }
result.push(children.filter(isTruthy)); result.push(children.filter(isTruthy));
return result; if (filter) {
return filter(result);
} else {
return result;
}
}; };
return { return {

Loading…
Cancel
Save