From bac0e0ff887e0fb5548d072fadd9421d80660d6f Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 29 Mar 2016 15:35:40 +0200 Subject: [PATCH] implement hyperjson filtering --- www/common/hyperjson.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/www/common/hyperjson.js b/www/common/hyperjson.js index 31a2caf08..71ba71987 100644 --- a/www/common/hyperjson.js +++ b/www/common/hyperjson.js @@ -47,7 +47,7 @@ define([], function () { return x; }; - var DOM2HyperJSON = function(el, predicate){ + var DOM2HyperJSON = function(el, predicate, filter){ if(!el.tagName && el.nodeType === Node.TEXT_NODE){ return el.textContent; } @@ -111,12 +111,16 @@ define([], function () { i = 0; 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)); - return result; + if (filter) { + return filter(result); + } else { + return result; + } }; return {