From d0d8cd0bcf36b4982bc97b26d4a9f7b52b6a09c5 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 10 Apr 2014 09:40:57 -0700 Subject: [PATCH] fix DOM layout for more than 2 nested nodes --- spec/LayoutSpec.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/LayoutSpec.js b/spec/LayoutSpec.js index 0004c618..0432a430 100755 --- a/spec/LayoutSpec.js +++ b/spec/LayoutSpec.js @@ -53,18 +53,18 @@ function computeDOMLayout(node) { var div = renderNode(body, node); - function buildLayout(parentRect, div) { + function buildLayout(absoluteRect, div) { var rect = div.getBoundingClientRect(); var result = { width: rect.width, height: rect.height, - top: rect.top - parentRect.top, - left: rect.left - parentRect.left + top: rect.top - absoluteRect.top, + left: rect.left - absoluteRect.left }; var children = []; for (var child = div.firstChild; child; child = child.nextSibling) { - children.push(buildLayout(result, child)); + children.push(buildLayout(rect, child)); } if (children.length) { result.children = children; @@ -492,7 +492,7 @@ describe('Layout', function() { } } function randChildren(node, chance) { - while (Math.random() < chance) { + while (rng.nextFloat() < chance) { if (!node.children) { node.children = []; } @@ -514,8 +514,8 @@ describe('Layout', function() { for (var i = 0; i < 100; ++i) { var node = generateRandomNode(); - expect({node: node, layout: computeLayout(node)}) - .toEqual({node: node, layout: computeDOMLayout(node)}); + expect({i: i, node: node, layout: computeLayout(node)}) + .toEqual({i: i, node: node, layout: computeDOMLayout(node)}); } })