Draggable + Sortable: Fixed blockFrames. Added unit tests specifically for draggable since it should be moving up to "core" file shortly

This commit is contained in:
Dave Stein 2013-02-18 17:13:29 -05:00
parent d438973983
commit 894d4c157a
3 changed files with 89 additions and 12 deletions

View File

@ -47,6 +47,87 @@ test("No options, absolute", function() {
TestHelpers.draggable.shouldMove(el); TestHelpers.draggable.shouldMove(el);
}); });
test("_blockFrames, absolute parent", function() {
expect( 3 );
var el = $("#draggable1").draggable(),
parent = $("<div style='width: 600px; height: 600px; position: absolute; top: 300px; left; 400px;'>"),
iframe = $("<iframe src='about:blank' width='500' height='500' style='position: absolute; top: 25px; left: 30px;'>"),
left, top;
parent.append( iframe );
$("#qunit-fixture").prepend( parent );
el.on( "drag", function() {
var block = iframe.next();
left = block.css("left");
top = block.css("top");
});
TestHelpers.draggable.shouldMove(el);
equal( left, "30px" );
equal( top, "25px" );
});
test("_blockFrames, relative parent", function() {
expect( 3 );
var el = $("#draggable1").draggable(),
parent = $("<div style='width: 600px; height: 600px; position: relative; top: 300px; left; 400px;'>"),
iframe = $("<iframe src='about:blank' width='500' height='500' style='position: absolute; top: 25px; left: 30px;'>"),
left, top;
parent.append( iframe );
$("#qunit-fixture").prepend( parent );
el.on( "drag", function() {
var block = iframe.next();
left = block.css("left");
top = block.css("top");
});
TestHelpers.draggable.shouldMove(el);
equal( left, "30px" );
equal( top, "25px" );
});
test("_blockFrames, static parent", function() {
expect( 3 );
var el = $("#draggable1").draggable(),
parent = $("<div style='width: 600px; height: 600px; margin-top: 300px; margin-left: 400px;'>"),
iframe = $("<iframe src='about:blank' width='500' height='500' style='position: relative; top: 25px; left: 30px;'>"),
left, top;
parent.append( iframe );
$("#qunit-fixture").prepend( parent );
el.on( "drag", function() {
var block = iframe.next();
left = block.css("left");
top = block.css("top");
});
TestHelpers.draggable.shouldMove(el);
equal( left, "430px" );
equal( top, "325px" );
});
test("resizable handle with complex markup (#8756 / #8757)", function() { test("resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 ); expect( 2 );

View File

@ -447,18 +447,16 @@ $.widget( "ui.draggable", $.ui.interaction, {
_blockFrames: function() { _blockFrames: function() {
this.iframeBlocks = this.document.find( "iframe" ).map(function() { this.iframeBlocks = this.document.find( "iframe" ).map(function() {
var iframe = $( this ), var iframe = $( this );
iframeOffset = iframe.offset();
return $( "<div>" ) return $( "<div>" )
.css({ .css({
position: "absolute", position: "absolute",
width: iframe.outerWidth(), width: iframe.outerWidth(),
height: iframe.outerHeight(), height: iframe.outerHeight()
top: iframeOffset.top,
left: iframeOffset.left
}) })
.appendTo( iframe.parent() )[0]; .appendTo( iframe.parent() )
.offset( iframe.offset() )[0];
}); });
}, },

View File

@ -447,18 +447,16 @@ $.widget( "ui.sortable", $.ui.interaction, {
_blockFrames: function() { _blockFrames: function() {
this.iframeBlocks = this.document.find( "iframe" ).map(function() { this.iframeBlocks = this.document.find( "iframe" ).map(function() {
var iframe = $( this ), var iframe = $( this );
iframeOffset = iframe.offset();
return $( "<div>" ) return $( "<div>" )
.css({ .css({
position: "absolute", position: "absolute",
width: iframe.outerWidth(), width: iframe.outerWidth(),
height: iframe.outerHeight(), height: iframe.outerHeight()
top: iframeOffset.top,
left: iframeOffset.left
}) })
.appendTo( iframe.parent() )[0]; .appendTo( iframe.parent() )
.offset( iframe.offset() )[0];
}); });
}, },