|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let Event = function( src, props ){ |
|
this.recycle( src, props ); |
|
}; |
|
|
|
function returnFalse(){ |
|
return false; |
|
} |
|
|
|
function returnTrue(){ |
|
return true; |
|
} |
|
|
|
|
|
Event.prototype = { |
|
instanceString: function(){ |
|
return 'event'; |
|
}, |
|
|
|
recycle: function( src, props ){ |
|
this.isImmediatePropagationStopped = this.isPropagationStopped = this.isDefaultPrevented = returnFalse; |
|
|
|
if( src != null && src.preventDefault ){ |
|
this.type = src.type; |
|
|
|
|
|
|
|
this.isDefaultPrevented = ( src.defaultPrevented ) ? returnTrue : returnFalse; |
|
|
|
} else if( src != null && src.type ){ |
|
props = src; |
|
|
|
} else { |
|
this.type = src; |
|
} |
|
|
|
|
|
if( props != null ){ |
|
|
|
this.originalEvent = props.originalEvent; |
|
this.type = props.type != null ? props.type : this.type; |
|
this.cy = props.cy; |
|
this.target = props.target; |
|
this.position = props.position; |
|
this.renderedPosition = props.renderedPosition; |
|
this.namespace = props.namespace; |
|
this.layout = props.layout; |
|
} |
|
|
|
if( this.cy != null && this.position != null && this.renderedPosition == null ){ |
|
|
|
let pos = this.position; |
|
let zoom = this.cy.zoom(); |
|
let pan = this.cy.pan(); |
|
|
|
this.renderedPosition = { |
|
x: pos.x * zoom + pan.x, |
|
y: pos.y * zoom + pan.y |
|
}; |
|
} |
|
|
|
|
|
this.timeStamp = src && src.timeStamp || Date.now(); |
|
}, |
|
|
|
preventDefault: function(){ |
|
this.isDefaultPrevented = returnTrue; |
|
|
|
let e = this.originalEvent; |
|
if( !e ){ |
|
return; |
|
} |
|
|
|
|
|
if( e.preventDefault ){ |
|
e.preventDefault(); |
|
} |
|
}, |
|
|
|
stopPropagation: function(){ |
|
this.isPropagationStopped = returnTrue; |
|
|
|
let e = this.originalEvent; |
|
if( !e ){ |
|
return; |
|
} |
|
|
|
|
|
if( e.stopPropagation ){ |
|
e.stopPropagation(); |
|
} |
|
}, |
|
|
|
stopImmediatePropagation: function(){ |
|
this.isImmediatePropagationStopped = returnTrue; |
|
this.stopPropagation(); |
|
}, |
|
|
|
isDefaultPrevented: returnFalse, |
|
isPropagationStopped: returnFalse, |
|
isImmediatePropagationStopped: returnFalse |
|
}; |
|
|
|
export default Event; |
|
|