From 7e6e8999ff83027fc6c88bfff27d8aa25b91722d Mon Sep 17 00:00:00 2001 From: Alex Vinober Date: Wed, 11 Oct 2017 17:20:38 -0400 Subject: [PATCH 1/4] Check if not a left-click, then bail out of onStart --- src/components/dragelement/index.js | 4 ++++ test/jasmine/tests/dragelement_test.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/components/dragelement/index.js b/src/components/dragelement/index.js index b2396952d18..a4107720f62 100644 --- a/src/components/dragelement/index.js +++ b/src/components/dragelement/index.js @@ -78,6 +78,10 @@ dragElement.init = function init(options) { element.ontouchstart = onStart; function onStart(e) { + if(e.button && e.button === 2) { // right click + return; + } + // make dragging and dragged into properties of gd // so that others can look at and modify them gd._dragged = false; diff --git a/test/jasmine/tests/dragelement_test.js b/test/jasmine/tests/dragelement_test.js index a0151c95d78..60ad3e3daa7 100644 --- a/test/jasmine/tests/dragelement_test.js +++ b/test/jasmine/tests/dragelement_test.js @@ -122,6 +122,19 @@ describe('dragElement', function() { expect(countCoverSlip()).toEqual(0); }); + it('should not add a cover slip div to the DOM when right click', function() { + function countCoverSlip() { + return d3.selectAll('.dragcover').size(); + } + + var options = { element: this.element, gd: this.gd }; + dragElement.init(options); + + options.element.onmousedown({button: 2}) + + expect(countCoverSlip()).toEqual(0); + }); + it('should fire off click event when down/up without dragging', function() { var options = { element: this.element, gd: this.gd }; dragElement.init(options); From 7c2b91e223fb0d6f0f98faac4d579af63117de86 Mon Sep 17 00:00:00 2001 From: Alex Vinober Date: Wed, 11 Oct 2017 17:20:38 -0400 Subject: [PATCH 2/4] Check if not a left-click, then bail out of onStart --- src/components/dragelement/index.js | 4 ++++ test/jasmine/tests/dragelement_test.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/components/dragelement/index.js b/src/components/dragelement/index.js index b2396952d18..a4107720f62 100644 --- a/src/components/dragelement/index.js +++ b/src/components/dragelement/index.js @@ -78,6 +78,10 @@ dragElement.init = function init(options) { element.ontouchstart = onStart; function onStart(e) { + if(e.button && e.button === 2) { // right click + return; + } + // make dragging and dragged into properties of gd // so that others can look at and modify them gd._dragged = false; diff --git a/test/jasmine/tests/dragelement_test.js b/test/jasmine/tests/dragelement_test.js index a0151c95d78..60ad3e3daa7 100644 --- a/test/jasmine/tests/dragelement_test.js +++ b/test/jasmine/tests/dragelement_test.js @@ -122,6 +122,19 @@ describe('dragElement', function() { expect(countCoverSlip()).toEqual(0); }); + it('should not add a cover slip div to the DOM when right click', function() { + function countCoverSlip() { + return d3.selectAll('.dragcover').size(); + } + + var options = { element: this.element, gd: this.gd }; + dragElement.init(options); + + options.element.onmousedown({button: 2}) + + expect(countCoverSlip()).toEqual(0); + }); + it('should fire off click event when down/up without dragging', function() { var options = { element: this.element, gd: this.gd }; dragElement.init(options); From fa3a06675ede854ac46efa426e1634ff50f669c1 Mon Sep 17 00:00:00 2001 From: Alex Vinober Date: Mon, 16 Oct 2017 11:28:53 -0400 Subject: [PATCH 3/4] Right click test, buttons instead button, test updated --- src/components/dragelement/index.js | 2 +- test/jasmine/tests/dragelement_test.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/dragelement/index.js b/src/components/dragelement/index.js index a4107720f62..67da40c4332 100644 --- a/src/components/dragelement/index.js +++ b/src/components/dragelement/index.js @@ -78,7 +78,7 @@ dragElement.init = function init(options) { element.ontouchstart = onStart; function onStart(e) { - if(e.button && e.button === 2) { // right click + if(e.buttons && e.buttons === 2) { // right click return; } diff --git a/test/jasmine/tests/dragelement_test.js b/test/jasmine/tests/dragelement_test.js index 60ad3e3daa7..92b2b075f0f 100644 --- a/test/jasmine/tests/dragelement_test.js +++ b/test/jasmine/tests/dragelement_test.js @@ -130,8 +130,7 @@ describe('dragElement', function() { var options = { element: this.element, gd: this.gd }; dragElement.init(options); - options.element.onmousedown({button: 2}) - + mouseEvent('mousedown', this.x, this.y, { buttons: 2 }); expect(countCoverSlip()).toEqual(0); }); From a33d1e764aeefaaa11d1aaf259e1e9f0db12d7a7 Mon Sep 17 00:00:00 2001 From: Alex Vinober Date: Mon, 16 Oct 2017 12:02:05 -0400 Subject: [PATCH 4/4] Test updated: countCoverSlip moved to upper level, one more check, that handler won't being called on right click --- test/jasmine/tests/dragelement_test.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/jasmine/tests/dragelement_test.js b/test/jasmine/tests/dragelement_test.js index 92b2b075f0f..74326a13c58 100644 --- a/test/jasmine/tests/dragelement_test.js +++ b/test/jasmine/tests/dragelement_test.js @@ -30,6 +30,10 @@ describe('dragElement', function() { afterEach(destroyGraphDiv); + function countCoverSlip() { + return d3.selectAll('.dragcover').size(); + } + it('should init drag element', function() { var options = { element: this.element, gd: this.gd }; dragElement.init(options); @@ -103,10 +107,6 @@ describe('dragElement', function() { }); it('should add a cover slip div to the DOM', function() { - function countCoverSlip() { - return d3.selectAll('.dragcover').size(); - } - var options = { element: this.element, gd: this.gd }; dragElement.init(options); @@ -123,15 +123,21 @@ describe('dragElement', function() { }); it('should not add a cover slip div to the DOM when right click', function() { - function countCoverSlip() { - return d3.selectAll('.dragcover').size(); - } - var options = { element: this.element, gd: this.gd }; dragElement.init(options); + var mockObj = { + handleClick: function() {} + }; + spyOn(mockObj, 'handleClick'); + + this.element.onclick = mockObj.handleClick; + mouseEvent('mousedown', this.x, this.y, { buttons: 2 }); expect(countCoverSlip()).toEqual(0); + + mouseEvent('mouseup', this.x, this.y); + expect(mockObj.handleClick).not.toHaveBeenCalled(); }); it('should fire off click event when down/up without dragging', function() {