Skip to content

Commit

Permalink
Draggable: Recalculate hash offset on start after plugins run
Browse files Browse the repository at this point in the history
 Fixes #6884
  • Loading branch information
mikesherov committed Aug 17, 2014
1 parent cdcb391 commit b5846be
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
39 changes: 39 additions & 0 deletions tests/unit/draggable/draggable_events.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -118,8 +118,47 @@ test( "stopping the stop callback", function() {
}); });


ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" ); ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
});

// http://bugs.jqueryui.com/ticket/6884
// Draggable: ui.offset.left differs between the "start" and "drag" hooks
test( "position and offset in hash is consistent between start, drag, and stop", function() {
expect( 4 );

var startPos, startOffset, dragPos, dragOffset, stopPos, stopOffset;

element = $( "<div style='margin: 2px;'></div>" ).appendTo( "#qunit-fixture" );

element.draggable({
start: function( event, ui ) {
startPos = ui.position;
startOffset = ui.offset;
},
drag: function( event, ui ) {
dragPos = ui.position;
dragOffset = ui.offset;
},
stop: function( event, ui ) {
stopPos = ui.position;
stopOffset = ui.offset;
}
});

element.simulate( "drag", {
dx: 10,
dy: 10,
moves: 1
});


startPos.left += 10;
startPos.top += 10;
startOffset.left += 10;
startOffset.top += 10;


deepEqual( startPos, dragPos, "start position equals drag position plus distance" );
deepEqual( dragPos, stopPos, "drag position equals stop position" );
deepEqual( startOffset, dragOffset, "start offset equals drag offset plus distance" );
deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
}); });


})( jQuery ); })( jQuery );
5 changes: 3 additions & 2 deletions ui/draggable.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -614,9 +614,10 @@ $.widget("ui.draggable", $.ui.mouse, {
ui = ui || this._uiHash(); ui = ui || this._uiHash();
$.ui.plugin.call( this, type, [ event, ui, this ], true ); $.ui.plugin.call( this, type, [ event, ui, this ], true );


// The absolute position has to be recalculated after plugins // Absolute position and offset (see #6884 ) have to be recalculated after plugins
if ( type === "drag" ) { if ( /^(drag|start|stop)/.test( type ) ) {
this.positionAbs = this._convertPositionTo( "absolute" ); this.positionAbs = this._convertPositionTo( "absolute" );
ui.offset = this.positionAbs;
} }
return $.Widget.prototype._trigger.call( this, type, event, ui ); return $.Widget.prototype._trigger.call( this, type, event, ui );
}, },
Expand Down

0 comments on commit b5846be

Please sign in to comment.