mirror of
https://github.com/bpmn-io/bpmn-js.git
synced 2025-08-16 04:41:02 +08:00

committed by
Ricardo Matias

parent
6011de1c4a
commit
c14a87e5ad
56
lib/features/modeling/ModelingUtil.js
Normal file
56
lib/features/modeling/ModelingUtil.js
Normal file
@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
var find = require('lodash/collection/find');
|
||||
|
||||
|
||||
function getParents(element) {
|
||||
|
||||
var parents = [];
|
||||
|
||||
while (element) {
|
||||
element = element.parent;
|
||||
|
||||
if (element) {
|
||||
parents.push(element);
|
||||
}
|
||||
}
|
||||
|
||||
return parents;
|
||||
}
|
||||
|
||||
module.exports.getParents = getParents;
|
||||
|
||||
|
||||
function getSharedParent(a, b) {
|
||||
|
||||
var parentsA = getParents(a),
|
||||
parentsB = getParents(b);
|
||||
|
||||
return find(parentsA, function(parent) {
|
||||
return parentsB.indexOf(parent) !== -1;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.getSharedParent = getSharedParent;
|
||||
|
||||
/**
|
||||
* Is an element of the given BPMN type?
|
||||
*
|
||||
* @param {djs.model.Base|ModdleElement} element
|
||||
* @param {String} type
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function is(element, type) {
|
||||
var bo = getBusinessObject(element);
|
||||
|
||||
return bo && bo.$instanceOf(type);
|
||||
}
|
||||
|
||||
module.exports.is = is;
|
||||
|
||||
|
||||
function getBusinessObject(element) {
|
||||
return (element && element.businessObject) || element;
|
||||
}
|
||||
|
||||
module.exports.getBusinessObject = getBusinessObject;
|
Reference in New Issue
Block a user