diff --git a/src/components/dragelement/index.js b/src/components/dragelement/index.js index b2396952d18..67da40c4332 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.buttons && e.buttons === 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..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); @@ -122,6 +122,24 @@ describe('dragElement', function() { expect(countCoverSlip()).toEqual(0); }); + it('should not add a cover slip div to the DOM when right click', function() { + 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() { var options = { element: this.element, gd: this.gd }; dragElement.init(options);