Skip to content

Commit

Permalink
fix(draggable): handle both touch and click events
Browse files Browse the repository at this point in the history
Fixes #207, #236, #329, and #380
  • Loading branch information
vieron committed Jun 16, 2014
1 parent 7d22e6c commit 021a6c2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/jquery.draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
var dir_map = { x : 'left', y : 'top' };
var isTouch = !!('ontouchstart' in window);
var pointer_events = {
start: isTouch ? 'touchstart.gridster-draggable' : 'mousedown.gridster-draggable',
move: isTouch ? 'touchmove.gridster-draggable' : 'mousemove.gridster-draggable',
end: isTouch ? 'touchend.gridster-draggable' : 'mouseup.gridster-draggable'
start: 'touchstart.gridster-draggable mousedown.gridster-draggable',
move: 'touchmove.gridster-draggable mousemove.gridster-draggable',
end: 'touchend.gridster-draggable mouseup.gridster-draggable'
};

var capitalize = function(str) {
Expand Down Expand Up @@ -111,7 +111,7 @@


fn.get_mouse_pos = function(e) {
if (isTouch) {
if (e.originalEvent && e.originalEvent.touches) {
var oe = e.originalEvent;
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
}
Expand Down Expand Up @@ -235,6 +235,7 @@

fn.drag_handler = function(e) {
var node = e.target.nodeName;
// skip if drag is disabled, or click was not done with the mouse primary button
if (this.disabled || e.which !== 1 && !isTouch) {
return;
}
Expand Down

0 comments on commit 021a6c2

Please sign in to comment.