Skip to content

Commit b5846be

Browse files
committed
Draggable: Recalculate hash offset on start after plugins run
Fixes #6884
1 parent cdcb391 commit b5846be

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

tests/unit/draggable/draggable_events.js

+39
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,47 @@ test( "stopping the stop callback", function() {
118118
});
119119

120120
ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
121+
});
122+
123+
// http://bugs.jqueryui.com/ticket/6884
124+
// Draggable: ui.offset.left differs between the "start" and "drag" hooks
125+
test( "position and offset in hash is consistent between start, drag, and stop", function() {
126+
expect( 4 );
127+
128+
var startPos, startOffset, dragPos, dragOffset, stopPos, stopOffset;
129+
130+
element = $( "<div style='margin: 2px;'></div>" ).appendTo( "#qunit-fixture" );
131+
132+
element.draggable({
133+
start: function( event, ui ) {
134+
startPos = ui.position;
135+
startOffset = ui.offset;
136+
},
137+
drag: function( event, ui ) {
138+
dragPos = ui.position;
139+
dragOffset = ui.offset;
140+
},
141+
stop: function( event, ui ) {
142+
stopPos = ui.position;
143+
stopOffset = ui.offset;
144+
}
145+
});
146+
147+
element.simulate( "drag", {
148+
dx: 10,
149+
dy: 10,
150+
moves: 1
151+
});
121152

153+
startPos.left += 10;
154+
startPos.top += 10;
155+
startOffset.left += 10;
156+
startOffset.top += 10;
122157

158+
deepEqual( startPos, dragPos, "start position equals drag position plus distance" );
159+
deepEqual( dragPos, stopPos, "drag position equals stop position" );
160+
deepEqual( startOffset, dragOffset, "start offset equals drag offset plus distance" );
161+
deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
123162
});
124163

125164
})( jQuery );

ui/draggable.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,10 @@ $.widget("ui.draggable", $.ui.mouse, {
614614
ui = ui || this._uiHash();
615615
$.ui.plugin.call( this, type, [ event, ui, this ], true );
616616

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

0 commit comments

Comments
 (0)