From e38d786bdf91bf0aa52a0194f0eb06f74d3482f1 Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Wed, 28 Jan 2015 20:39:36 -0600 Subject: [PATCH] Add a method to Utils for finding a child of the root object --- modules/Material/Extras/js/utils.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/Material/Extras/js/utils.js b/modules/Material/Extras/js/utils.js index 7a701b0..c71da26 100644 --- a/modules/Material/Extras/js/utils.js +++ b/modules/Material/Extras/js/utils.js @@ -36,6 +36,32 @@ function generateID() { return guid } +function findRoot(obj) { + while (obj.parent) { + obj = obj.parent + } + + return obj +} + +function findRootChild(obj, objectName) { + obj = findRoot(obj) + + var childs = new Array(0); + childs.push(obj) + while (childs.length > 0) { + if (childs[0].objectName == objectName) { + return childs[0] + } + for (var i in childs[0].data) { + childs.push(childs[0].data[i]) + } + childs.splice(0, 1); + } + return null; +} + + function findChild(obj,objectName) { var childs = new Array(0); childs.push(obj)