Skip to content

Commit 4e4987e

Browse files
authored
Merge pull request #7 from FormAPI/master
Prevent click event after item has been dragged, and ignore the right mouse button
2 parents a2d3a3c + 66dc109 commit 4e4987e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/MouseBackend.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export default class MouseBackend {
4444
this.handleWindowMoveCapture.bind(this)
4545
this.handleWindowMoveEndCapture =
4646
this.handleWindowMoveEndCapture.bind(this)
47+
this.handleWindowClick =
48+
this.handleWindowClick.bind(this)
49+
this.handleWindowDragstart =
50+
this.handleWindowDragstart.bind(this)
4751
}
4852

4953
setup() {
@@ -64,6 +68,10 @@ export default class MouseBackend {
6468
this.handleWindowMoveCapture, true)
6569
window.addEventListener('mouseup',
6670
this.handleWindowMoveEndCapture, true)
71+
window.addEventListener('click',
72+
this.handleWindowClick, true)
73+
window.addEventListener('dragstart',
74+
this.handleWindowDragstart, true)
6775
}
6876

6977
getSourceClientOffset (sourceId) {
@@ -86,6 +94,10 @@ export default class MouseBackend {
8694
'mousemove', this.handleWindowMoveCapture, true)
8795
window.removeEventListener(
8896
'mouseup', this.handleWindowMoveEndCapture, true)
97+
window.removeEventListener(
98+
'click', this.handleWindowClick, true)
99+
window.removeEventListener(
100+
'dragstart', this.handleWindowDragstart, true)
89101
}
90102

91103
connectDragSource(sourceId, node) {
@@ -124,7 +136,9 @@ export default class MouseBackend {
124136
this.moveStartSourceIds = []
125137
}
126138

127-
handleMoveStart (sourceId) {
139+
handleMoveStart (sourceId, e) {
140+
// Ignore right mouse button.
141+
if (e.which === 3) return
128142
this.moveStartSourceIds.unshift(sourceId)
129143
}
130144

@@ -185,6 +199,7 @@ export default class MouseBackend {
185199
this.moveStartSourceIds = null
186200
return
187201
}
202+
this.preventClick = true
188203

189204
e.preventDefault()
190205

@@ -195,6 +210,16 @@ export default class MouseBackend {
195210
this.actions.endDrag()
196211
}
197212

213+
handleWindowClick(e) {
214+
if (this.preventClick) e.stopPropagation()
215+
this.preventClick = false
216+
}
217+
218+
// Disable drag on images (Firefox)
219+
handleWindowDragstart(e) {
220+
e.preventDefault()
221+
}
222+
198223
installSourceNodeRemovalObserver (node) {
199224
this.uninstallSourceNodeRemovalObserver()
200225

0 commit comments

Comments
 (0)