public/javascripts/right/dnd-src.js in right-rails-1.1.0 vs public/javascripts/right/dnd-src.js in right-rails-1.2.0

- old
+ new

@@ -1,7 +1,7 @@ /** - * Drag'n'Drop module v2.2.0 + * Drag'n'Drop module v2.2.2 * http://rightjs.org/plugins/drag-n-drop * * Copyright (C) 2009-2011 Nikolay Nemshilov */ (function(window, document, RightJS) { @@ -26,11 +26,11 @@ * * Copyright (C) 2009-2011 Nikolay Nemshilov */ var Draggable = new Class(Observer, { extend: { - version: '2.2.0', + version: '2.2.2', EVENTS: $w('before start drag stop drop'), Options: { handle: null, // a handle element that will start the drag @@ -77,11 +77,14 @@ */ initialize: function(element, options) { this.element = $(element); this.$super(options); - this.element.draggable = this.init(); + this._dragStart = R(this.dragStart).bind(this); + this.handle.onMousedown(this._dragStart); + + this.element.draggable = this; }, /** * detaches the mouse observers out of the draggable element * @@ -137,37 +140,32 @@ return this; }, // protected - init: function() { - // caching the callback so that we could detach it later - this._dragStart = R(this.dragStart).bind(this); - - this.handle.onMousedown(this._dragStart); - - return this; - }, - // handles the event start dragStart: function(event) { + if (this._drag) { return false; } else { this._drag = true; } + this.fire('before', this, event.stop()); // calculating the positions diff var position = this.element.position(); this.xDiff = event.pageX - position.x; this.yDiff = event.pageY - position.y; - // grabbing the relative position diffs - var relative_position = { - y: R(this.element.getStyle('top')).toFloat(), - x: R(this.element.getStyle('left')).toFloat() - }; + // grabbing the relative position diffs for nested spaces + this.rxDiff = this.ryDiff = 0; + this.element.parents().reverse().each(function(parent) { + if (parent.getStyle('position') !== 'static') { + parent = parent.position(); - this.rxDiff = isNaN(relative_position.x) ? 0 : (relative_position.x - position.x); - this.ryDiff = isNaN(relative_position.y) ? 0 : (relative_position.y - position.y); + this.rxDiff = - parent.x; + this.ryDiff = - parent.y; + } + }, this); // preserving the element sizes var size = { x: this.element.getStyle('width'), y: this.element.getStyle('height') @@ -195,11 +193,10 @@ if (this.options.moveOut) { this.element.insertTo(document.body); } - // caching the window scrolls this.winScrolls = $(window).scrolls(); this.winSizes = $(window).size(); Draggable.current = this.calcConstraints().fire('start', this, event); @@ -264,10 +261,12 @@ // notifying the droppables for the drop Droppable.checkDrop(event, this); if (this.options.revert) { this.revert(); + } else { + this._drag = false; } Draggable.current = null; this.fire('stop', this, event); @@ -283,9 +282,10 @@ position: this.clone.getStyle('position'), zIndex: this.clone.getStyle('zIndex') || '' }) ); } + this._drag = false; }, // calculates the constraints calcConstraints: function() { var axis = this.options.axis; \ No newline at end of file