Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added middle click mouse down managment #3764

Merged
merged 2 commits into from
Mar 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@
*/
fireRightClick: false,

/**
* Indicates if the canvas can fire middle click events
* @type Boolean
* @since 1.7.8
* @default
*/
fireMiddleClick: false,

/**
* @private
*/
Expand Down
8 changes: 8 additions & 0 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@
return;
}

var isMiddleClick = 'which' in e ? e.which === 2 : e.button === 1;
if (isMiddleClick) {
if (this.fireMiddleClick) {
this._handleEvent(e, 'down', target ? target : null);
}
return;
}

if (this.isDrawingMode) {
this._onMouseDownInDrawingMode(e);
return;
Expand Down
25 changes: 25 additions & 0 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1726,4 +1726,29 @@
ok(typeof InheritedCanvasClass === 'function');
});

test('mouse:down with different buttons', function() {
var clickCount = 0;
function mouseHandler() {
clickCount++;
}
canvas.on('mouse:down', mouseHandler);
canvas.fireMiddleClick = false;
canvas.fireRightClick = false;
canvas._currentTransform = false;
canvas.isDrawingMode = false;
canvas.__onMouseDown({ which: 1 });
equal(clickCount, 1, 'mouse down fired');
clickCount = 0;
canvas.__onMouseDown({ which: 3 });
equal(clickCount, 0, 'rightclick did not fire a mouse:down event');
canvas.fireRightClick = true;
canvas.__onMouseDown({ which: 3 });
equal(clickCount, 1, 'rightclick did fire a mouse:down event');
clickCount = 0;
canvas.__onMouseDown({ which: 2 });
equal(clickCount, 0, 'middleClick did not fire a mouse:down event');
canvas.fireMiddleClick = true;
canvas.__onMouseDown({ which: 2 });
equal(clickCount, 1, 'middleClick did fire a mouse:down event');
});
})();