From 5425699f433a5cf71330c218774f093efa261023 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 29 Feb 2016 15:27:11 +0100 Subject: [PATCH] check if possible parent exists before checking if it contains another element --- www/common/treesome.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/www/common/treesome.js b/www/common/treesome.js index 6fd504a56..65b0b2c58 100644 --- a/www/common/treesome.js +++ b/www/common/treesome.js @@ -18,7 +18,7 @@ define([], function () { if (tree.some(root.children[last], predicate)) { return true; } // otherwise none of the nodes inside it matched. - + // check the node itself if (predicate(root.children[last], last)) { return true; @@ -32,7 +32,7 @@ define([], function () { var someText = tree.someIncludingText = function (root, predicate) { // take the index of the last element in the current root var last = root.childNodes.length - 1; - + // it might be a leaf node if (last < 0) { return false; } @@ -45,7 +45,7 @@ define([], function () { if (tree.someIncludingText(root.childNodes[last], predicate)) { return true; } // otherwise none of the nodes inside it matched. - + // check the node itself if (predicate(root.childNodes[last], last)) { return true; @@ -96,13 +96,13 @@ define([], function () { // not being used internally, but is useful externally tree.contains = function (el, root) { - return el && root.contains && root.contains(el); + return el && root && root.contains && root.contains(el); }; var siblingCount = tree.siblingCount = function (el) { return el.parentNode.childNodes.length; }; - + var childCount = tree.childCount = function (el) { return el.childNodes.length; };