Skip to content

Commit 8eca7b8

Browse files
antishokmikesherov
authored andcommitted
Draggable: Set explicit width/height instead of right/bottom css.
Fixes #7772
1 parent 48ea2aa commit 8eca7b8

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

tests/unit/draggable/draggable.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<div id="main">
8383
<div id="draggable1" style="background: green; width: 200px; height: 100px; position: relative; top: 0; left: 0;">Relative</div>
8484
<div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span><em>Absolute</em></span></div>
85+
<div id="draggable3" style="background: green; position: absolute; right: 5px; bottom: 5px; padding: 7px; border: 3px solid black;"><span><em>Absolute right-bottom</em></span></div>
8586
<div id="droppable" style="background: green; width: 200px; height: 100px; position: absolute; top: 110px; left: 110px;"><span>Absolute</span></div>
8687
<div id="main-forceScrollable"></div>
8788
</div>

tests/unit/draggable/draggable_core.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ test( "element types", function() {
2525
el.append("<tr><td>content</td></tr>");
2626
}
2727

28+
// intrinsic height is incorrect in FF for buttons with no content
29+
// https://bugzilla.mozilla.org/show_bug.cgi?id=471763
30+
// Support: FF
31+
if ( typeName === "button" ) {
32+
el.text( "button" );
33+
}
34+
2835
el.draggable({ cancel: "" });
2936
offsetBefore = el.offset();
3037
el.simulate( "drag", {
@@ -35,8 +42,8 @@ test( "element types", function() {
3542

3643
// Support: FF, Chrome, and IE9,
3744
// there are some rounding errors in so we can't say equal, we have to settle for close enough
38-
closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
39-
closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
45+
closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + "> left" );
46+
closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + "> top" );
4047
el.draggable("destroy");
4148
el.remove();
4249
});
@@ -317,4 +324,28 @@ test( "ui-draggable-handle managed correctly in nested draggables", function() {
317324
ok( child.hasClass( "ui-draggable-handle" ), "child retains class name on destroy" );
318325
});
319326

327+
// http://bugs.jqueryui.com/ticket/7772
328+
// when css 'right' is set, element resizes on drag
329+
test( "setting right/bottom css shouldn't cause resize", function() {
330+
expect( 3 );
331+
332+
var finalOffset,
333+
element = $( "#draggable3" ),
334+
origWidth = element.width(),
335+
origHeight = element.height(),
336+
origOffset = element.offset();
337+
338+
element.draggable();
339+
340+
TestHelpers.draggable.move( element, -50, -50 );
341+
342+
finalOffset = element.offset();
343+
finalOffset.left += 50;
344+
finalOffset.top += 50;
345+
346+
equal( element.width(), origWidth, "element retains width" );
347+
equal( element.height(), origHeight, "element retains height" );
348+
deepEqual( finalOffset, origOffset, "element moves the correct distance" );
349+
});
350+
320351
})( jQuery );

ui/draggable.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ $.widget("ui.draggable", $.ui.mouse, {
220220
$.ui.ddmanager.prepareOffsets(this, event);
221221
}
222222

223+
// Reset helper's right/bottom css if they're set and set explicit width/height instead
224+
// as this prevents resizing of elements with right/bottom set (see #7772)
225+
this._normalizeRightBottom();
226+
223227
this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
224228

225229
//If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
@@ -632,6 +636,17 @@ $.widget("ui.draggable", $.ui.mouse, {
632636
}
633637
},
634638

639+
_normalizeRightBottom: function() {
640+
if ( this.options.axis !== "y" && this.helper.css( "right" ) !== "auto" ) {
641+
this.helper.width( this.helper.width() );
642+
this.helper.css( "right", "auto" );
643+
}
644+
if ( this.options.axis !== "x" && this.helper.css( "bottom" ) !== "auto" ) {
645+
this.helper.height( this.helper.height() );
646+
this.helper.css( "bottom", "auto" );
647+
}
648+
},
649+
635650
// From now on bulk stuff - mainly helpers
636651

637652
_trigger: function( type, event, ui ) {

0 commit comments

Comments
 (0)