2015-04-06 18:33:25 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 02:05:00 +00:00
|
|
|
"ui/widgets/resizable"
|
2015-04-07 14:30:07 +00:00
|
|
|
], function( $, testHelper ) {
|
2009-02-02 14:36:08 +00:00
|
|
|
|
|
|
|
module("resizable: events");
|
|
|
|
|
2012-07-10 08:02:25 +00:00
|
|
|
test("start", function() {
|
|
|
|
|
|
|
|
expect(5);
|
|
|
|
|
|
|
|
var count = 0,
|
|
|
|
handle = ".ui-resizable-se";
|
|
|
|
|
|
|
|
$("#resizable1").resizable({
|
|
|
|
handles: "all",
|
|
|
|
start: function(event, ui) {
|
|
|
|
equal( ui.size.width, 100, "compare width" );
|
|
|
|
equal( ui.size.height, 100, "compare height" );
|
|
|
|
equal( ui.originalSize.width, 100, "compare original width" );
|
|
|
|
equal( ui.originalSize.height, 100, "compare original height" );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag(handle, 50, 50);
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
equal(count, 1, "start callback should happen exactly once");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
test( "resize", function() {
|
2012-07-10 08:02:25 +00:00
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
expect( 9 );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
var count = 0,
|
|
|
|
handle = ".ui-resizable-se";
|
|
|
|
|
|
|
|
$("#resizable1").resizable({
|
|
|
|
handles: "all",
|
2012-12-12 08:59:11 +00:00
|
|
|
resize: function( event, ui ) {
|
|
|
|
if ( count === 0 ) {
|
|
|
|
equal( ui.size.width, 125, "compare width" );
|
|
|
|
equal( ui.size.height, 125, "compare height" );
|
2012-07-10 08:02:25 +00:00
|
|
|
equal( ui.originalSize.width, 100, "compare original width" );
|
|
|
|
equal( ui.originalSize.height, 100, "compare original height" );
|
|
|
|
} else {
|
|
|
|
equal( ui.size.width, 150, "compare width" );
|
|
|
|
equal( ui.size.height, 150, "compare height" );
|
|
|
|
equal( ui.originalSize.width, 100, "compare original width" );
|
|
|
|
equal( ui.originalSize.height, 100, "compare original height" );
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag( handle, 50, 50 );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
equal( count, 2, "resize callback should happen exactly once per size adjustment" );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
test( "resize (min/max dimensions)", function() {
|
2012-07-10 08:02:25 +00:00
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
expect( 5 );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
var count = 0,
|
|
|
|
handle = ".ui-resizable-se";
|
|
|
|
|
|
|
|
$("#resizable1").resizable({
|
|
|
|
handles: "all",
|
|
|
|
minWidth: 60,
|
|
|
|
minHeight: 60,
|
|
|
|
maxWidth: 100,
|
|
|
|
maxHeight: 100,
|
2012-12-12 08:59:11 +00:00
|
|
|
resize: function( event, ui ) {
|
2012-07-10 08:02:25 +00:00
|
|
|
equal( ui.size.width, 60, "compare width" );
|
|
|
|
equal( ui.size.height, 60, "compare height" );
|
|
|
|
equal( ui.originalSize.width, 100, "compare original width" );
|
|
|
|
equal( ui.originalSize.height, 100, "compare original height" );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag( handle, -200, -200 );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
equal( count, 1, "resize callback should happen exactly once per size adjustment" );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
test( "resize (containment)", function() {
|
2012-07-10 08:02:25 +00:00
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
expect( 5 );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
var count = 0,
|
|
|
|
handle = ".ui-resizable-se",
|
|
|
|
container = $("#resizable1").wrap("<div>").parent().css({
|
|
|
|
height: "100px",
|
|
|
|
width: "100px"
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#resizable1").resizable({
|
|
|
|
handles: "all",
|
|
|
|
containment: container,
|
2012-12-12 08:59:11 +00:00
|
|
|
resize: function( event, ui ) {
|
|
|
|
equal( ui.size.width, 10, "compare width" );
|
|
|
|
equal( ui.size.height, 10, "compare height" );
|
2012-07-10 08:02:25 +00:00
|
|
|
equal( ui.originalSize.width, 100, "compare original width" );
|
|
|
|
equal( ui.originalSize.height, 100, "compare original height" );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
// Prove you can't resize outside containment by dragging southeast corner southeast
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag( handle, 100, 100 );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
2012-12-12 08:59:11 +00:00
|
|
|
// Prove you can't resize outside containment by dragging southeast corner northwest
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag( handle, -200, -200 );
|
2012-12-12 08:59:11 +00:00
|
|
|
|
|
|
|
equal( count, 1, "resize callback should happen exactly once per size adjustment" );
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resize (grid)", function() {
|
|
|
|
|
|
|
|
expect(5);
|
|
|
|
|
|
|
|
var count = 0,
|
|
|
|
handle = ".ui-resizable-se";
|
|
|
|
|
|
|
|
$("#resizable1").resizable({
|
|
|
|
handles: "all",
|
|
|
|
grid: 50,
|
|
|
|
resize: function(event, ui) {
|
|
|
|
equal( ui.size.width, 150, "compare width" );
|
|
|
|
equal( ui.size.height, 150, "compare height" );
|
|
|
|
equal( ui.originalSize.width, 100, "compare original width" );
|
|
|
|
equal( ui.originalSize.height, 100, "compare original height" );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag(handle, 50, 50);
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
equal(count, 1, "resize callback should happen exactly once per grid-unit size adjustment");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-07-24 17:32:34 +00:00
|
|
|
test( "resize, custom adjustment", function() {
|
|
|
|
expect( 4 );
|
|
|
|
|
|
|
|
var handle = ".ui-resizable-se",
|
|
|
|
element = $( "#resizable1" ).resizable({
|
|
|
|
resize: function( event, ui ) {
|
|
|
|
ui.size.width = 100;
|
|
|
|
ui.size.height = 200;
|
|
|
|
ui.position.left = 300;
|
|
|
|
ui.position.top = 400;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag( handle, 50, 50 );
|
2014-07-24 17:32:34 +00:00
|
|
|
|
|
|
|
equal( element.width(), 100, "resize event can control width" );
|
|
|
|
equal( element.height(), 200, "resize event can control height" );
|
|
|
|
equal( element.position().left, 300, "resize event can control left" );
|
|
|
|
equal( element.position().top, 400, "resize event can control top" );
|
|
|
|
});
|
|
|
|
|
2012-07-10 08:02:25 +00:00
|
|
|
test("stop", function() {
|
|
|
|
|
|
|
|
expect(5);
|
|
|
|
|
|
|
|
var count = 0,
|
|
|
|
handle = ".ui-resizable-se";
|
2012-12-12 08:59:11 +00:00
|
|
|
|
2012-07-10 08:02:25 +00:00
|
|
|
$("#resizable1").resizable({
|
|
|
|
handles: "all",
|
|
|
|
stop: function(event, ui) {
|
|
|
|
equal( ui.size.width, 150, "compare width" );
|
|
|
|
equal( ui.size.height, 150, "compare height" );
|
|
|
|
equal( ui.originalSize.width, 100, "compare original width" );
|
|
|
|
equal( ui.originalSize.height, 100, "compare original height" );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag(handle, 50, 50);
|
2012-07-10 08:02:25 +00:00
|
|
|
|
|
|
|
equal(count, 1, "stop callback should happen exactly once");
|
|
|
|
|
|
|
|
});
|
2012-10-23 14:36:42 +00:00
|
|
|
|
2013-05-16 11:26:13 +00:00
|
|
|
test( "resize (containment) works with parent with negative offset", function() {
|
|
|
|
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
var widthBefore, widthAfter,
|
|
|
|
handle = ".ui-resizable-e",
|
|
|
|
target = $( "#resizable1" ),
|
|
|
|
absoluteContainer = target.wrap( "<div />" ).parent(),
|
|
|
|
fixedContainer = absoluteContainer.wrap( "<div />" ).parent(),
|
|
|
|
increaseWidthBy = 50;
|
|
|
|
|
|
|
|
// position fixed container in window top left
|
|
|
|
fixedContainer.css({
|
|
|
|
width: 400,
|
|
|
|
height: 100,
|
|
|
|
position: "fixed",
|
|
|
|
top: 0,
|
|
|
|
left: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
// position absolute container within fixed on slightly outside window
|
|
|
|
absoluteContainer.css({
|
|
|
|
width: 400,
|
|
|
|
height: 100,
|
|
|
|
position: "absolute",
|
|
|
|
top: 0,
|
|
|
|
left: -50
|
|
|
|
});
|
|
|
|
|
|
|
|
// set up resizable to be contained within absolute container
|
|
|
|
target.resizable({
|
|
|
|
handles: "all",
|
|
|
|
containment: "parent"
|
|
|
|
}).css({
|
|
|
|
width: 300
|
|
|
|
});
|
|
|
|
|
|
|
|
widthBefore = target.width();
|
|
|
|
|
2015-04-07 14:30:07 +00:00
|
|
|
testHelper.drag( handle, increaseWidthBy, 0 );
|
2013-05-16 11:26:13 +00:00
|
|
|
|
|
|
|
widthAfter = target.width();
|
|
|
|
|
|
|
|
equal( widthAfter, ( widthBefore + increaseWidthBy ), "resizable width should be increased by the value dragged" );
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-06 18:33:25 +00:00
|
|
|
} );
|