diff --git a/src/jquery.draggable.js b/src/jquery.draggable.js index 3a3d49eb6..262b9af95 100644 --- a/src/jquery.draggable.js +++ b/src/jquery.draggable.js @@ -19,7 +19,6 @@ // stop : function(e){} }; - var $body = $(document.body); var $window = $(window); @@ -51,6 +50,7 @@ */ function Draggable(el, options) { this.options = $.extend({}, defaults, options); + this.$body = $(document.body); this.$container = $(el); this.$dragitems = $(this.options.items, this.$container); this.is_dragging = false; @@ -164,7 +164,7 @@ this.mouse_init_pos = this.get_mouse_pos(e); this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top; - $body.on('mousemove.draggable', function(mme){ + this.$body.on('mousemove.draggable', function(mme){ var mouse_actual_pos = self.get_mouse_pos(mme); var diff_x = Math.abs( @@ -279,9 +279,9 @@ this.$container.on('mousedown.draggable', this.options.items, $.proxy( this.drag_handler, this)); - $body.on('mouseup.draggable', $.proxy(function(e) { + this.$body.on('mouseup.draggable', $.proxy(function(e) { this.is_dragging = false; - $body.off('mousemove.draggable'); + this.$body.off('mousemove.draggable'); if (this.drag_start) { this.on_dragstop(e); } @@ -291,7 +291,7 @@ fn.disable = function(){ this.$container.off('mousedown.draggable'); - $body.off('mouseup.draggable'); + this.$body.off('mouseup.draggable'); };