2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
some
|
|
|
|
} from 'min-dash';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import { is } from '../../../util/ModelUtil';
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-22 11:43:36 +00:00
|
|
|
* Return true if element has any of the given types.
|
2015-10-09 23:40:52 +00:00
|
|
|
*
|
|
|
|
* @param {djs.model.Base} element
|
|
|
|
* @param {Array<String>} types
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function isAny(element, types) {
|
2018-03-22 09:22:37 +00:00
|
|
|
return some(types, function(t) {
|
2015-10-09 23:40:52 +00:00
|
|
|
return is(element, t);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-22 11:43:36 +00:00
|
|
|
* Return the parent of the element with any of the given types.
|
2015-10-09 23:40:52 +00:00
|
|
|
*
|
|
|
|
* @param {djs.model.Base} element
|
|
|
|
* @param {String|Array<String>} anyType
|
|
|
|
*
|
|
|
|
* @return {djs.model.Base}
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function getParent(element, anyType) {
|
2015-10-09 23:40:52 +00:00
|
|
|
|
|
|
|
if (typeof anyType === 'string') {
|
|
|
|
anyType = [ anyType ];
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((element = element.parent)) {
|
|
|
|
if (isAny(element, anyType)) {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2018-04-02 19:01:53 +00:00
|
|
|
}
|