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