Skip to content

Commit

Permalink
Remove cy prefix on event fields, because we don't merge with the o…
Browse files Browse the repository at this point in the history
…riginal event (as left open); e.g. `cyTarget` => `target` cytoscape#1537
  • Loading branch information
maxkfranz committed Mar 7, 2017
1 parent e3d2480 commit a58ab2f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
14 changes: 7 additions & 7 deletions src/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,12 @@ var define = {
if( eventsIsEvent ){ // then just get the object
evt = evtObj;

evt.cyTarget = evt.cyTarget || triggerer;
evt.target = evt.target || triggerer;
evt.cy = evt.cy || cy;

} else { // then we have to make one
evt = new Event( evtObj, {
cyTarget: triggerer,
target: triggerer,
cy: cy,
namespace: evtObj.namespace
} );
Expand All @@ -480,12 +480,12 @@ var define = {
}

// create a rendered position based on the passed position
if( evt.cyPosition ){
var pos = evt.cyPosition;
if( evt.position ){
var pos = evt.position;
var zoom = cy.zoom();
var pan = cy.pan();

evt.cyRenderedPosition = {
evt.renderedPosition = {
x: pos.x * zoom + pan.x,
y: pos.y * zoom + pan.y
};
Expand All @@ -503,7 +503,7 @@ var define = {
var lis = listeners[ k ];
var nsMatches = !lis.namespace || lis.namespace === evt.namespace || lis.namespace === define.event.universalNamespace;
var typeMatches = lis.type === evt.type;
var targetMatches = lis.delegated ? ( triggerer !== evt.cyTarget && is.element( evt.cyTarget ) && lis.selObj.matches( evt.cyTarget ) ) : (true); // we're not going to validate the hierarchy; that's too expensive
var targetMatches = lis.delegated ? ( triggerer !== evt.target && is.element( evt.target ) && lis.selObj.matches( evt.target ) ) : (true); // we're not going to validate the hierarchy; that's too expensive
var listenerMatches = nsMatches && typeMatches && targetMatches;

if( listenerMatches ){ // then trigger it
Expand Down Expand Up @@ -540,7 +540,7 @@ var define = {
}

// run the callback
var context = lis.delegated ? evt.cyTarget : triggerer;
var context = lis.delegated ? evt.target : triggerer;
var ret = lis.callback.apply( context, args );

if( ret === false || evt.isPropagationStopped() ){
Expand Down
6 changes: 3 additions & 3 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ var Event = function( src, props ){
// more efficient to manually copy fields we use
this.type = props.type !== undefined ? props.type : this.type;
this.cy = props.cy;
this.cyTarget = props.cyTarget;
this.cyPosition = props.cyPosition;
this.cyRenderedPosition = props.cyRenderedPosition;
this.target = props.target;
this.position = props.position;
this.renderedPosition = props.renderedPosition;
this.namespace = props.namespace;
this.layout = props.layout;
this.data = props.data;
Expand Down
8 changes: 4 additions & 4 deletions src/extensions/renderer/base/coord-ele-math.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ BRp.registerCalculationListeners = function(){
// nodes

.on('position.* style.* free.* bounds.*', 'node', function onDirtyModNode( e ){
var node = e.cyTarget;
var node = e.target;

enqueue( node, e );
enqueue( node.connectedEdges(), e );
})

.on('add.* background.*', 'node', function onDirtyAddNode( e ){
var ele = e.cyTarget;
var ele = e.target;

enqueue( ele, e );
})

// edges

.on('add.* style.*', 'edge', function onDirtyEdge( e ){
var edge = e.cyTarget;
var edge = e.target;

enqueue( edge, e );
enqueue( edge.parallelEdges(), e );
})

.on('remove.*', 'edge', function onDirtyRemoveEdge( e ){
var edge = e.cyTarget;
var edge = e.target;
var pEdges = edge.parallelEdges();

for( var i = 0; i < pEdges.length; i++ ){
Expand Down
70 changes: 35 additions & 35 deletions src/extensions/renderer/base/load-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,12 @@ BRp.load = function(){
if( ele ){
ele.trigger( new Event( e, {
type: 'taphold',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} ) );
} else {
cy.trigger( new Event( e, {
type: 'taphold',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} ) );
}
}
Expand All @@ -460,7 +460,7 @@ BRp.load = function(){

var cxtEvt = new Event( e, {
type: 'cxttapstart',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

if( near ){
Expand Down Expand Up @@ -491,7 +491,7 @@ BRp.load = function(){

var grabEvent = new Event( e, {
type: 'grab',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

setGrabTarget( near );
Expand Down Expand Up @@ -526,7 +526,7 @@ BRp.load = function(){
}

triggerEvents( near, [ 'mousedown', 'tapstart', 'vmousedown' ], e, {
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

if( near == null ){
Expand Down Expand Up @@ -613,7 +613,7 @@ BRp.load = function(){
preventDefault = true;

triggerEvents( near, [ 'mousemove', 'vmousemove', 'tapdrag' ], e, {
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

var goIntoBoxMode = function(){
Expand All @@ -636,7 +636,7 @@ BRp.load = function(){
if( isOverThresholdDrag ){
var cxtEvt = new Event( e, {
type: 'cxtdrag',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

if( down ){
Expand All @@ -652,7 +652,7 @@ BRp.load = function(){
if( r.hoverData.cxtOver ){
r.hoverData.cxtOver.trigger( new Event( e, {
type: 'cxtdragout',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} ) );
}

Expand All @@ -661,7 +661,7 @@ BRp.load = function(){
if( near ){
near.trigger( new Event( e, {
type: 'cxtdragover',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} ) );
}

Expand Down Expand Up @@ -737,13 +737,13 @@ BRp.load = function(){

if( last ){
triggerEvents( last, [ 'mouseout', 'tapdragout' ], e, {
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );
}

if( near ){
triggerEvents( near, [ 'mouseover', 'tapdragover' ], e, {
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );
}

Expand Down Expand Up @@ -864,7 +864,7 @@ BRp.load = function(){
if( r.hoverData.which === 3 ){
var cxtEvt = new Event( e, {
type: 'cxttapend',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

if( down ){
Expand All @@ -876,7 +876,7 @@ BRp.load = function(){
if( !r.hoverData.cxtDragged ){
var cxtTap = new Event( e, {
type: 'cxttap',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

if( down ){
Expand Down Expand Up @@ -909,7 +909,7 @@ BRp.load = function(){
}

triggerEvents( near, [ 'mouseup', 'tapend', 'vmouseup' ], e, {
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );

if(
Expand All @@ -918,7 +918,7 @@ BRp.load = function(){
&& !r.hoverData.selecting // not box selection
){
triggerEvents( down, ['click', 'tap', 'vclick'], e, {
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} );
}

Expand Down Expand Up @@ -1096,7 +1096,7 @@ BRp.load = function(){

r.cy.trigger( new Event( e, {
type: 'mouseout',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} ) );
}, false );

Expand All @@ -1105,7 +1105,7 @@ BRp.load = function(){

r.cy.trigger( new Event( e, {
type: 'mouseover',
cyPosition: { x: pos[0], y: pos[1] }
position: { x: pos[0], y: pos[1] }
} ) );
}, false );

Expand Down Expand Up @@ -1185,21 +1185,21 @@ BRp.load = function(){
if( near1 && near1.isNode() ){
near1.activate().trigger( new Event( e, {
type: 'cxttapstart',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} ) );
r.touchData.start = near1;

} else if( near2 && near2.isNode() ){
near2.activate().trigger( new Event( e, {
type: 'cxttapstart',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} ) );
r.touchData.start = near2;

} else {
cy.trigger( new Event( e, {
type: 'cxttapstart',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} ) );
}

Expand Down Expand Up @@ -1252,13 +1252,13 @@ BRp.load = function(){

near.trigger( new Event( e, {
type: 'grab',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} ) );
}
}

triggerEvents( near, [ 'touchstart', 'tapstart', 'vmousedown' ], e, {
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

if( near == null ){
Expand Down Expand Up @@ -1286,7 +1286,7 @@ BRp.load = function(){
&& !r.touchData.selecting // box selection shouldn't allow taphold through
){
triggerEvents( r.touchData.start, [ 'taphold' ], e, {
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

if( !r.touchData.start ){
Expand Down Expand Up @@ -1366,7 +1366,7 @@ BRp.load = function(){

var cxtEvt = new Event( e, {
type: 'cxttapend',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

if( r.touchData.start ){
Expand All @@ -1387,7 +1387,7 @@ BRp.load = function(){
if( capture && r.touchData.cxt ){
var cxtEvt = new Event( e, {
type: 'cxtdrag',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );
r.data.bgActivePosistion = undefined;
r.redrawHint( 'select', true );
Expand All @@ -1408,7 +1408,7 @@ BRp.load = function(){
if( r.touchData.cxtOver ){
r.touchData.cxtOver.trigger( new Event( e, {
type: 'cxtdragout',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} ) );
}

Expand All @@ -1417,7 +1417,7 @@ BRp.load = function(){
if( near ){
near.trigger( new Event( e, {
type: 'cxtdragover',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} ) );

}
Expand Down Expand Up @@ -1640,12 +1640,12 @@ BRp.load = function(){
// touchmove
{
triggerEvents( (start || near), [ 'touchmove', 'tapdrag', 'vmousemove' ], e, {
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

if( ( !start || !start.grabbed() ) && near != last ){
if( last ){ last.trigger( new Event( e, { type: 'tapdragout', cyPosition: { x: now[0], y: now[1] } } ) ); }
if( near ){ near.trigger( new Event( e, { type: 'tapdragover', cyPosition: { x: now[0], y: now[1] } } ) ); }
if( last ){ last.trigger( new Event( e, { type: 'tapdragout', position: { x: now[0], y: now[1] } } ) ); }
if( near ){ near.trigger( new Event( e, { type: 'tapdragover', position: { x: now[0], y: now[1] } } ) ); }
}

r.touchData.last = near;
Expand Down Expand Up @@ -1762,7 +1762,7 @@ BRp.load = function(){
if( r.touchData.cxt ){
ctxTapend = new Event( e, {
type: 'cxttapend',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

if( start ){
Expand All @@ -1774,7 +1774,7 @@ BRp.load = function(){
if( !r.touchData.cxtDragged ){
var ctxTap = new Event( e, {
type: 'cxttap',
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

if( start ){
Expand Down Expand Up @@ -1859,7 +1859,7 @@ BRp.load = function(){
}

triggerEvents( start, [ 'touchend', 'tapend', 'vmouseup', 'tapdragout' ], e, {
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

start.unactivate();
Expand All @@ -1870,7 +1870,7 @@ BRp.load = function(){
var near = r.findNearestElement( now[0], now[1], true );

triggerEvents( near, [ 'touchend', 'tapend', 'vmouseup', 'tapdragout' ], e, {
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );

}
Expand Down Expand Up @@ -1907,7 +1907,7 @@ BRp.load = function(){
// Tap event, roughly same as mouse click event for touch
if( !r.touchData.singleTouchMoved ){
triggerEvents( start, [ 'tap', 'vclick' ], e, {
cyPosition: { x: now[0], y: now[1] }
position: { x: now[0], y: now[1] }
} );
}

Expand Down
2 changes: 1 addition & 1 deletion test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ describe('Events', function(){
expect( e ).to.be.ok;
expect( e ).to.have.property('type', 'foo');
expect( e ).to.have.property('cy', cy);
expect( e ).to.have.property('cyTarget', cy);
expect( e ).to.have.property('target', cy);
expect( e ).to.have.property('namespace', '.bar');
expect( e.timeStamp ).to.be.a('number');

Expand Down

0 comments on commit a58ab2f

Please sign in to comment.