2015-08-24 13:31:47 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var assign = require('lodash/object/assign');
|
|
|
|
|
|
|
|
var EventBus = require('diagram-js/lib/core/EventBus');
|
|
|
|
|
|
|
|
var TestHelper = require('../TestHelper');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an event with global coordinates
|
|
|
|
* computed based on the loaded diagrams canvas position and the
|
|
|
|
* specified canvas local coordinates.
|
|
|
|
*
|
|
|
|
* @param {Point} point of the event local the canvas (closure)
|
|
|
|
* @param {Object} data
|
|
|
|
*
|
|
|
|
* @return {Event} event, scoped to the given canvas
|
|
|
|
*/
|
|
|
|
function createCanvasEvent(position, data) {
|
|
|
|
|
|
|
|
return TestHelper.getBpmnJS().invoke(function(canvas) {
|
|
|
|
|
|
|
|
var target = canvas._svg;
|
|
|
|
|
|
|
|
var clientRect = canvas._container.getBoundingClientRect();
|
|
|
|
|
2015-10-20 08:50:48 +00:00
|
|
|
var absolutePosition = {
|
|
|
|
x: position.x + clientRect.left,
|
|
|
|
y: position.y + clientRect.top
|
|
|
|
};
|
|
|
|
|
|
|
|
return createEvent(target, absolutePosition, data);
|
2015-08-24 13:31:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.createCanvasEvent = createCanvasEvent;
|
|
|
|
|
|
|
|
|
|
|
|
function createEvent(target, position, data) {
|
|
|
|
|
|
|
|
// unwrap snapsvg gfx
|
|
|
|
target = target.node || target;
|
|
|
|
|
|
|
|
data = assign({
|
|
|
|
target: target,
|
2016-04-27 07:24:13 +00:00
|
|
|
x: position.x,
|
|
|
|
y: position.y,
|
2015-08-24 13:31:47 +00:00
|
|
|
clientX: position.x,
|
|
|
|
clientY: position.y,
|
|
|
|
offsetX: position.x,
|
|
|
|
offsetY: position.y
|
|
|
|
}, data || {});
|
|
|
|
|
|
|
|
var event = new EventBus.Event();
|
|
|
|
|
|
|
|
event.init(data);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2016-08-31 09:02:04 +00:00
|
|
|
module.exports.createEvent = createEvent;
|