From ec9c1cf6f42adbac695c1c142d28b6a8a53a8616 Mon Sep 17 00:00:00 2001 From: Dave Stein Date: Sun, 6 Nov 2011 16:20:56 -0500 Subject: [PATCH] Draggable: Proper use of ._trigger for detecting preventDefault. _uiHash now returns position and helper - removed offset. --- ui/jquery.ui.draggable.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index 390c85a05..4677eaf30 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -124,7 +124,7 @@ $.widget( "ui.draggable", { }, _mouseDown: function( event ) { - var newLeft, newTop; + var newLeft, newTop, allowed; // Prevent text selection, among other things event.preventDefault(); @@ -183,11 +183,10 @@ $.widget( "ui.draggable", { this._preparePosition( event ); - this._trigger( "start", event, this._uiHash() ); + allowed = this._trigger( "start", event, this._uiHash() ); - // TODO: should user be able to change position of draggable, if event stopped? // If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes - if ( event.cancelBubble === true ) { + if ( allowed !== true ) { this.doc.unbind( "." + this.widgetName ); return; } @@ -201,15 +200,15 @@ $.widget( "ui.draggable", { }, _mouseMove: function( event ) { - var newLeft, newTop; - + var newLeft, newTop, allowed; + this._preparePosition( event ); - this._trigger( "drag", event, this._uiHash() ); - - // TODO: should user be able to change position of draggable, if event stopped? + allowed = this._trigger( "drag", event, this._uiHash() ); + + // If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes - if ( event.cancelBubble === true ) { + if ( allowed !== true ) { this.doc.unbind( "." + this.widgetName ); return; } @@ -221,14 +220,15 @@ $.widget( "ui.draggable", { }, _mouseUp: function( event ) { + + var allowed; this._preparePosition( event ); - this._trigger( "stop", event, this._uiHash() ); + allowed = this._trigger( "stop", event, this._uiHash() ); - // TODO: should user be able to change position of draggable, if event stopped? // If user stops propagation, leave helper there, disallow any CSS changes - if ( event.cancelBubble !== true ) { + if ( allowed === true ) { this._setCss( event ); @@ -293,10 +293,17 @@ $.widget( "ui.draggable", { }, _uiHash: function( event ) { - return { - position: this.position, - offset: this.offset + var ret = { + position: this.position + // offset: this.offset }; + + if ( this.options.helper ) { + ret.helper = this.dragEl; + } + + return ret; + } });