Skip to content

Commit 021a6c2

Browse files
committedJun 16, 2014
fix(draggable): handle both touch and click events
Fixes #207, #236, #329, and #380
1 parent 7d22e6c commit 021a6c2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
 

‎src/jquery.draggable.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
var dir_map = { x : 'left', y : 'top' };
3030
var isTouch = !!('ontouchstart' in window);
3131
var pointer_events = {
32-
start: isTouch ? 'touchstart.gridster-draggable' : 'mousedown.gridster-draggable',
33-
move: isTouch ? 'touchmove.gridster-draggable' : 'mousemove.gridster-draggable',
34-
end: isTouch ? 'touchend.gridster-draggable' : 'mouseup.gridster-draggable'
32+
start: 'touchstart.gridster-draggable mousedown.gridster-draggable',
33+
move: 'touchmove.gridster-draggable mousemove.gridster-draggable',
34+
end: 'touchend.gridster-draggable mouseup.gridster-draggable'
3535
};
3636

3737
var capitalize = function(str) {
@@ -111,7 +111,7 @@
111111

112112

113113
fn.get_mouse_pos = function(e) {
114-
if (isTouch) {
114+
if (e.originalEvent && e.originalEvent.touches) {
115115
var oe = e.originalEvent;
116116
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
117117
}
@@ -235,6 +235,7 @@
235235

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

0 commit comments

Comments
 (0)
Please sign in to comment.