forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse_event.js
37 lines (32 loc) · 876 Bytes
/
mouse_event.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module.exports = function(type, x, y, opts) {
var fullOpts = {
bubbles: true,
clientX: x,
clientY: y
};
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
if(opts && opts.buttons) {
fullOpts.buttons = opts.buttons;
}
if(opts && opts.altKey) {
fullOpts.altKey = opts.altKey;
}
if(opts && opts.ctrlKey) {
fullOpts.ctrlKey = opts.ctrlKey;
}
if(opts && opts.metaKey) {
fullOpts.metaKey = opts.metaKey;
}
if(opts && opts.shiftKey) {
fullOpts.shiftKey = opts.shiftKey;
}
var el = (opts && opts.element) || document.elementFromPoint(x, y),
ev;
if(type === 'scroll') {
ev = new window.WheelEvent('wheel', opts);
} else {
ev = new window.MouseEvent(type, fullOpts);
}
el.dispatchEvent(ev);
return el;
};