2008-06-06 03:58:15 +00:00
|
|
|
/*
|
2009-02-02 07:12:37 +00:00
|
|
|
* draggable_core.js
|
2008-06-06 03:58:15 +00:00
|
|
|
*/
|
2009-02-01 00:25:58 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
(function( $ ) {
|
2008-06-06 06:34:09 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
var relativeElement, absoluteElement;
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
module( "draggable: core", {
|
|
|
|
setup: function() {
|
|
|
|
relativeElement = $("<div style='width: 200px; height: 100px;'>Relative</div>").appendTo("#qunit-fixture");
|
|
|
|
absoluteElement = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
|
|
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
relativeElement.remove();
|
|
|
|
absoluteElement.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "element types", function() {
|
|
|
|
var typeNames = (
|
|
|
|
"p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
|
|
|
|
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
|
|
|
|
",acronym,code,samp,kbd,var,img,hr" +
|
|
|
|
",input,button,label,select,iframe"
|
|
|
|
).split(",");
|
2008-06-07 06:09:04 +00:00
|
|
|
|
2012-11-09 20:02:12 +00:00
|
|
|
expect( typeNames.length * 2 );
|
2012-10-30 23:12:17 +00:00
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
$.each( typeNames, function( i ) {
|
2012-11-03 20:17:16 +00:00
|
|
|
var offsetBefore, offsetAfter,
|
2013-01-12 05:33:45 +00:00
|
|
|
typeName = typeNames[ i ],
|
|
|
|
el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
|
|
|
|
|
|
|
|
if ( typeName === "table" ) {
|
|
|
|
el.append("<tr><td>content</td></tr>");
|
|
|
|
}
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
el.draggable({ cancel: "" });
|
2012-10-30 23:12:17 +00:00
|
|
|
offsetBefore = el.offset();
|
2012-12-09 02:27:37 +00:00
|
|
|
el.simulate( "drag", {
|
|
|
|
dx: 50,
|
|
|
|
dy: 50
|
|
|
|
});
|
2012-11-03 20:17:16 +00:00
|
|
|
offsetAfter = el.offset();
|
2013-01-12 05:33:45 +00:00
|
|
|
|
|
|
|
// Support: FF, Chrome, and IE9,
|
|
|
|
// there are some rounding errors in so we can't say equal, we have to settle for close enough
|
|
|
|
closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
|
|
|
|
closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
|
2008-06-07 06:09:04 +00:00
|
|
|
el.draggable("destroy");
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "No options, relative", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
TestHelpers.draggable.shouldMove( relativeElement.draggable() );
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "No options, absolute", function() {
|
2012-10-30 23:12:17 +00:00
|
|
|
expect( 1 );
|
2013-01-12 05:33:45 +00:00
|
|
|
TestHelpers.draggable.shouldMove( absoluteElement.draggable() );
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
test( "resizable handle with complex markup (#8756 / #8757)", function() {
|
2012-11-19 14:06:36 +00:00
|
|
|
expect( 2 );
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
relativeElement
|
2012-11-19 14:06:36 +00:00
|
|
|
.append(
|
2012-12-26 13:08:48 +00:00
|
|
|
$("<div>")
|
2013-01-12 05:33:45 +00:00
|
|
|
.addClass("ui-resizable-handle ui-resizable-w")
|
|
|
|
.append( $("<div>") )
|
2012-11-19 14:06:36 +00:00
|
|
|
);
|
|
|
|
|
2012-12-26 13:08:48 +00:00
|
|
|
var handle = $(".ui-resizable-w div"),
|
2013-01-12 05:33:45 +00:00
|
|
|
target = relativeElement.draggable().resizable({ handles: "all" });
|
2012-11-19 14:06:36 +00:00
|
|
|
|
2012-12-09 02:27:37 +00:00
|
|
|
// todo: fix resizable so it doesn't require a mouseover
|
|
|
|
handle.simulate("mouseover").simulate( "drag", { dx: -50 } );
|
2012-11-19 14:06:36 +00:00
|
|
|
equal( target.width(), 250, "compare width" );
|
|
|
|
|
2012-12-09 02:27:37 +00:00
|
|
|
// todo: fix resizable so it doesn't require a mouseover
|
|
|
|
handle.simulate("mouseover").simulate( "drag", { dx: 50 } );
|
2012-11-19 14:06:36 +00:00
|
|
|
equal( target.width(), 200, "compare width" );
|
|
|
|
});
|
|
|
|
|
2013-01-12 05:33:45 +00:00
|
|
|
})( jQuery );
|