check if possible parent exists before checking if it contains another element
This commit is contained in:
@@ -18,7 +18,7 @@ define([], function () {
|
|||||||
if (tree.some(root.children[last], predicate)) {
|
if (tree.some(root.children[last], predicate)) {
|
||||||
return true;
|
return true;
|
||||||
} // otherwise none of the nodes inside it matched.
|
} // otherwise none of the nodes inside it matched.
|
||||||
|
|
||||||
// check the node itself
|
// check the node itself
|
||||||
if (predicate(root.children[last], last)) {
|
if (predicate(root.children[last], last)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -32,7 +32,7 @@ define([], function () {
|
|||||||
var someText = tree.someIncludingText = function (root, predicate) {
|
var someText = tree.someIncludingText = function (root, predicate) {
|
||||||
// take the index of the last element in the current root
|
// take the index of the last element in the current root
|
||||||
var last = root.childNodes.length - 1;
|
var last = root.childNodes.length - 1;
|
||||||
|
|
||||||
// it might be a leaf node
|
// it might be a leaf node
|
||||||
if (last < 0) { return false; }
|
if (last < 0) { return false; }
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ define([], function () {
|
|||||||
if (tree.someIncludingText(root.childNodes[last], predicate)) {
|
if (tree.someIncludingText(root.childNodes[last], predicate)) {
|
||||||
return true;
|
return true;
|
||||||
} // otherwise none of the nodes inside it matched.
|
} // otherwise none of the nodes inside it matched.
|
||||||
|
|
||||||
// check the node itself
|
// check the node itself
|
||||||
if (predicate(root.childNodes[last], last)) {
|
if (predicate(root.childNodes[last], last)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -96,13 +96,13 @@ define([], function () {
|
|||||||
|
|
||||||
// not being used internally, but is useful externally
|
// not being used internally, but is useful externally
|
||||||
tree.contains = function (el, root) {
|
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) {
|
var siblingCount = tree.siblingCount = function (el) {
|
||||||
return el.parentNode.childNodes.length;
|
return el.parentNode.childNodes.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
var childCount = tree.childCount = function (el) {
|
var childCount = tree.childCount = function (el) {
|
||||||
return el.childNodes.length;
|
return el.childNodes.length;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user