mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-02-05 21:53:48 +00:00
66 lines
1.1 KiB
JavaScript
66 lines
1.1 KiB
JavaScript
|
'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<String>} 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<String>} 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;
|