From d51613ea4a944f9a0438b777fa1f68e591ed9a18 Mon Sep 17 00:00:00 2001 From: Max Franz Date: Wed, 21 Sep 2016 15:41:43 -0400 Subject: [PATCH] Remove `cy` prefix on event fields, because we don't merge with the original event (as left open); e.g. `cyTarget` => `target` #1537 --- src/define.js | 14 ++-- src/event.js | 6 +- .../renderer/base/coord-ele-math.js | 8 +-- .../renderer/base/load-listeners.js | 70 +++++++++---------- test/events.js | 2 +- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/define.js b/src/define.js index 037302545e..cc12350596 100644 --- a/src/define.js +++ b/src/define.js @@ -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 } ); @@ -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 }; @@ -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 @@ -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() ){ diff --git a/src/event.js b/src/event.js index cd93ce07ec..dcf2ae1346 100644 --- a/src/event.js +++ b/src/event.js @@ -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; diff --git a/src/extensions/renderer/base/coord-ele-math.js b/src/extensions/renderer/base/coord-ele-math.js index 942d235143..90469fe270 100644 --- a/src/extensions/renderer/base/coord-ele-math.js +++ b/src/extensions/renderer/base/coord-ele-math.js @@ -38,7 +38,7 @@ BRp.registerCalculationListeners = function(){ // nodes .on('position.* style.* free.*', 'node', function onDirtyModNode( e ){ - var node = e.cyTarget; + var node = e.target; enqueue( node, e ); enqueue( node.connectedEdges(), e ); @@ -52,7 +52,7 @@ BRp.registerCalculationListeners = function(){ }) .on('add.* background.*', 'node', function onDirtyAddNode( e ){ - var ele = e.cyTarget; + var ele = e.target; enqueue( ele, e ); }) @@ -60,14 +60,14 @@ BRp.registerCalculationListeners = function(){ // 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++ ){ diff --git a/src/extensions/renderer/base/load-listeners.js b/src/extensions/renderer/base/load-listeners.js index 3f334a0619..c7d04dd246 100644 --- a/src/extensions/renderer/base/load-listeners.js +++ b/src/extensions/renderer/base/load-listeners.js @@ -368,12 +368,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] } } ) ); } } @@ -388,7 +388,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 ){ @@ -419,7 +419,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 ); @@ -454,7 +454,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 ){ @@ -568,7 +568,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] } } ); // trigger context drag if rmouse down @@ -577,7 +577,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 ){ @@ -593,7 +593,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] } } ) ); } @@ -602,7 +602,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] } } ) ); } @@ -687,13 +687,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] } } ); } @@ -803,7 +803,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 ){ @@ -815,7 +815,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 ){ @@ -848,7 +848,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( @@ -857,7 +857,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] } } ); } @@ -1026,7 +1026,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 ); @@ -1035,7 +1035,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 ); @@ -1113,21 +1113,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] } } ) ); r.touchData.start = null; } @@ -1181,13 +1181,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 ){ @@ -1223,7 +1223,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 ){ @@ -1287,7 +1287,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 ){ r.touchData.start.trigger( cxtEvt ); @@ -1302,7 +1302,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 ); @@ -1323,7 +1323,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] } } ) ); } @@ -1332,7 +1332,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] } } ) ); } @@ -1553,12 +1553,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; @@ -1675,7 +1675,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 ){ @@ -1687,7 +1687,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 ){ @@ -1772,7 +1772,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(); @@ -1783,7 +1783,7 @@ BRp.load = function(){ var near = r.findNearestElement( now[0], now[1], true, true ); triggerEvents( near, [ 'touchend', 'tapend', 'vmouseup', 'tapdragout' ], e, { - cyPosition: { x: now[0], y: now[1] } + position: { x: now[0], y: now[1] } } ); } @@ -1820,7 +1820,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] } } ); } diff --git a/test/events.js b/test/events.js index 1a72ddf14d..bf0fc36051 100644 --- a/test/events.js +++ b/test/events.js @@ -380,7 +380,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');