From 5a2e5a0a9a6117427038cdd9640852a72c5a05c2 Mon Sep 17 00:00:00 2001 From: Dave Stein Date: Tue, 11 Dec 2012 19:21:37 -0500 Subject: [PATCH] Draggable: Added revert backCompat with TODO for droppable strings, since that is not written yet --- ui/jquery.ui.draggable.js | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index 05d8d80cd..0701f9151 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -708,4 +708,47 @@ if ( $.uiBackCompat !== false ) { }); + // TODO: handle droppables + // revert option + $.widget( "ui.draggable", $.ui.draggable, { + options: { + revert: false + }, + + _create : function() { + + var self = this, + originalLeft, originalTop, originalPosition; + + this._super(); + + // No need to continue + if ( !this.options.revert ) { + return; + } + + this.element.on( "dragbeforestart", function( e, ui ) { + + // Cache the original css of draggable element to reset later + originalLeft = self.dragEl.css( 'left' ); + originalTop = self.dragEl.css( 'top' ); + originalPosition = self.dragEl.css( 'position' ); + + }); + + this.element.on( "dragstop", function( e, ui ) { + + // Reset to before drag + self.dragEl.css({ + left: originalLeft, + top: originalTop, + position: originalPosition + }); + + }); + + } + + }); + } \ No newline at end of file