Skip to content

Commit dd6c742

Browse files
hrosenbauervieron
authored andcommitted
fix(draggable): bind drag events to $document
$body won't receive mouseup if the cursor is outside the browser window, $document does
1 parent a4f3baf commit dd6c742

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/jquery.draggable.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
*/
6767
function Draggable(el, options) {
6868
this.options = $.extend({}, defaults, options);
69-
this.$body = $(document.body);
69+
this.$document = $(document);
7070
this.$container = $(el);
7171
this.$dragitems = $(this.options.items, this.$container);
7272
this.is_dragging = false;
@@ -94,10 +94,10 @@
9494
this.$container.on(pointer_events.start, this.options.items,
9595
$.proxy(this.drag_handler, this));
9696

97-
this.$body.on(pointer_events.end, $.proxy(function(e) {
97+
this.$document.on(pointer_events.end, $.proxy(function(e) {
9898
this.is_dragging = false;
9999
if (this.disabled) { return; }
100-
this.$body.off(pointer_events.move);
100+
this.$document.off(pointer_events.move);
101101
if (this.drag_start) {
102102
this.on_dragstop(e);
103103
}
@@ -251,7 +251,7 @@
251251
this.mouse_init_pos = this.get_mouse_pos(e);
252252
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
253253

254-
this.$body.on(pointer_events.move, function(mme) {
254+
this.$document.on(pointer_events.move, function(mme) {
255255
var mouse_actual_pos = self.get_mouse_pos(mme);
256256
var diff_x = Math.abs(
257257
mouse_actual_pos.left - self.mouse_init_pos.left);
@@ -376,7 +376,7 @@
376376
this.disable();
377377

378378
this.$container.off('.gridster-draggable');
379-
this.$body.off('.gridster-draggable');
379+
this.$document.off('.gridster-draggable');
380380
$(window).off('.gridster-draggable');
381381

382382
$.removeData(this.$container, 'drag');

0 commit comments

Comments
 (0)