diff --git a/www/common/convert.js b/www/common/convert.js index b95591e93..973881c80 100644 --- a/www/common/convert.js +++ b/www/common/convert.js @@ -5,7 +5,7 @@ define([ ], function (vdom, hyperjson, hyperscript) { // complain if you don't find the required APIs if (!(vdom && hyperjson && hyperscript)) { throw new Error(); } - + // Generate a matrix of conversions /* convert.dom.to.hjson, convert.hjson.to.dom, @@ -46,7 +46,7 @@ define([ return hyperjson.fromDOM(vdom.create(V)); } } - }, + }, convert = {}; Object.keys(methods).forEach(function (method) { convert[method] = { to: methods[method] }; diff --git a/www/common/hyperjson.js b/www/common/hyperjson.js index 660c62194..31a2caf08 100644 --- a/www/common/hyperjson.js +++ b/www/common/hyperjson.js @@ -47,13 +47,20 @@ define([], function () { return x; }; - var DOM2HyperJSON = function(el){ + var DOM2HyperJSON = function(el, predicate){ if(!el.tagName && el.nodeType === Node.TEXT_NODE){ return el.textContent; } if(!el.attributes){ return; } + + if (predicate) { + if (!predicate(el)) { + // shortcircuit + return; + } + } var attributes = {}; var i = 0; @@ -102,10 +109,12 @@ define([], function () { // js hint complains if we use 'var' here i = 0; + for(; i < el.childNodes.length; i++){ - children.push(DOM2HyperJSON(el.childNodes[i])); + children.push(DOM2HyperJSON(el.childNodes[i], predicate)); } - result.push(children); + + result.push(children.filter(isTruthy)); return result; };