1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | let Event = function( src, props ){
|
10 | this.recycle( src, props );
|
11 | };
|
12 |
|
13 | function returnFalse(){
|
14 | return false;
|
15 | }
|
16 |
|
17 | function returnTrue(){
|
18 | return true;
|
19 | }
|
20 |
|
21 |
|
22 | Event.prototype = {
|
23 | instanceString: function(){
|
24 | return 'event';
|
25 | },
|
26 |
|
27 | recycle: function( src, props ){
|
28 | this.isImmediatePropagationStopped = this.isPropagationStopped = this.isDefaultPrevented = returnFalse;
|
29 |
|
30 | if( src != null && src.preventDefault ){
|
31 | this.type = src.type;
|
32 |
|
33 |
|
34 |
|
35 | this.isDefaultPrevented = ( src.defaultPrevented ) ? returnTrue : returnFalse;
|
36 |
|
37 | } else if( src != null && src.type ){
|
38 | props = src;
|
39 |
|
40 | } else {
|
41 | this.type = src;
|
42 | }
|
43 |
|
44 |
|
45 | if( props != null ){
|
46 |
|
47 | this.originalEvent = props.originalEvent;
|
48 | this.type = props.type != null ? props.type : this.type;
|
49 | this.cy = props.cy;
|
50 | this.target = props.target;
|
51 | this.position = props.position;
|
52 | this.renderedPosition = props.renderedPosition;
|
53 | this.namespace = props.namespace;
|
54 | this.layout = props.layout;
|
55 | }
|
56 |
|
57 | if( this.cy != null && this.position != null && this.renderedPosition == null ){
|
58 |
|
59 | let pos = this.position;
|
60 | let zoom = this.cy.zoom();
|
61 | let pan = this.cy.pan();
|
62 |
|
63 | this.renderedPosition = {
|
64 | x: pos.x * zoom + pan.x,
|
65 | y: pos.y * zoom + pan.y
|
66 | };
|
67 | }
|
68 |
|
69 |
|
70 | this.timeStamp = src && src.timeStamp || Date.now();
|
71 | },
|
72 |
|
73 | preventDefault: function(){
|
74 | this.isDefaultPrevented = returnTrue;
|
75 |
|
76 | let e = this.originalEvent;
|
77 | if( !e ){
|
78 | return;
|
79 | }
|
80 |
|
81 |
|
82 | if( e.preventDefault ){
|
83 | e.preventDefault();
|
84 | }
|
85 | },
|
86 |
|
87 | stopPropagation: function(){
|
88 | this.isPropagationStopped = returnTrue;
|
89 |
|
90 | let e = this.originalEvent;
|
91 | if( !e ){
|
92 | return;
|
93 | }
|
94 |
|
95 |
|
96 | if( e.stopPropagation ){
|
97 | e.stopPropagation();
|
98 | }
|
99 | },
|
100 |
|
101 | stopImmediatePropagation: function(){
|
102 | this.isImmediatePropagationStopped = returnTrue;
|
103 | this.stopPropagation();
|
104 | },
|
105 |
|
106 | isDefaultPrevented: returnFalse,
|
107 | isPropagationStopped: returnFalse,
|
108 | isImmediatePropagationStopped: returnFalse
|
109 | };
|
110 |
|
111 | export default Event;
|