Skip to content

Commit

Permalink
Fix drag/drop bug that caused click event
Browse files Browse the repository at this point in the history
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
danielbeardsley committed Mar 13, 2012
1 parent e973091 commit 7324bab
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion draggables.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var Draggables = new Class({
mouseDown,
mouseDownEvent,
mouseOver,
disableClick,
snap = 10,
highlightClass = 'dragOver';

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 7324bab

Please sign in to comment.