Permalink
Browse files

Fix drag/drop bug that caused click event

A drag/drop operation was causing a click event after the drop. The mousedown
event and the mouseup event were happening on th same element, so the browser
fires a click event.

The only way to prevent this it seems is to temporarily disable click events
ont he whole document.  It's a hack, but at the moment, it seems like a bug in
browser logic that we'll have to deal with.
  • Loading branch information...
1 parent e973091 commit 7324bab5d706fa7046b7bc3cd5b594920f82c8b4 @danielbeardsley danielbeardsley committed Mar 13, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1 draggables.js
View
@@ -53,6 +53,7 @@ var Draggables = new Class({
mouseDown,
mouseDownEvent,
mouseOver,
+ disableClick,
snap = 10,
highlightClass = 'dragOver';
@@ -84,7 +85,14 @@ var Draggables = new Class({
var dropper = event.droppable;
stopDragging(dragging && dropper && mouseDown != dropper, event);
- })
+ event.stop();
+ });
+
+ // Temporarily disable click event after dragging
+ doc.addEvent('click', function(event){
+ if (disableClick)
+ event.stop();
+ });
doc.addEvent('keyup', function(event){
if(dragging && event.key == 'esc')
@@ -216,6 +224,14 @@ var Draggables = new Class({
mouseDown.setPosition({x:0,y:0});
mouseDown.removeClass('dragging');
root.setStyle('cursor', '');
+ if(event && event.stop)
+ event.stop();
+ // Temporarily disable all click events... as the event.stop() on
+ // a mouseup event doesn't stop the following click event.
+ disableClick = true;
+ setTimeout(function() {
+ disableClick = false;
+ }, 500);
}
reset();
}

0 comments on commit 7324bab

Please sign in to comment.