'use strict'; var any = require('lodash/collection/any'); var is = require('../../../util/ModelUtil').is; function getParents(element) { var parents = []; while (element) { element = element.parent; if (element) { parents.push(element); } } return parents; } module.exports.getParents = getParents; /** * Return true if element has any of the given types. * * @param {djs.model.Base} element * @param {Array} types * * @return {Boolean} */ function isAny(element, types) { return any(types, function(t) { return is(element, t); }); } module.exports.isAny = isAny; /** * Return the parent of the element with any of the given types. * * @param {djs.model.Base} element * @param {String|Array} anyType * * @return {djs.model.Base} */ function getParent(element, anyType) { if (typeof anyType === 'string') { anyType = [ anyType ]; } while ((element = element.parent)) { if (isAny(element, anyType)) { return element; } } return null; } module.exports.getParent = getParent;