From 73dd7818b1506581b13d1911e1f89e87bf4d70ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Wed, 29 Sep 2021 10:07:30 +0200 Subject: [PATCH 1/8] Adding support for containment --- ui/widgets/dialog.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js index 6fa585c40db..af148054993 100644 --- a/ui/widgets/dialog.js +++ b/ui/widgets/dialog.js @@ -95,7 +95,8 @@ $.widget( "ui.dialog", { open: null, resize: null, resizeStart: null, - resizeStop: null + resizeStop: null, + containment: "document" }, sizeRelatedOptions: { @@ -547,7 +548,7 @@ $.widget( "ui.dialog", { this.uiDialog.draggable( { cancel: ".ui-dialog-content, .ui-dialog-titlebar-close", handle: ".ui-dialog-titlebar", - containment: "document", + containment: options.containment, start: function( event, ui ) { that._addClass( $( this ), "ui-dialog-dragging" ); that._blockFrames(); From b0aafb4deb1d1edd7f92855d65739b27759b8f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Mon, 6 Dec 2021 12:10:33 +0100 Subject: [PATCH 2/8] Unittest for #1988 --- tests/unit/dialog/options.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 2de788a4461..0fa442fce94 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -569,4 +569,19 @@ QUnit.test( "Open followed by close during show effect", function( assert ) { }, 100 ); } ); +QUnit.test( "Dialog can't break out containment", function( assert ) { + assert.expect( 1 ); + var box = $( '
' ).css( { + height: '500px',border: '0px, margin:'0px', width:'500px', position: 'absolute', bottom: '0px', right: '0px', left: '50px', top: '50px' + } ).appendTo( "body" ), + element = $('
X
').dialog({containment: box, position: { at: "left top", of: box}}), // open on left top corner + dlg = element.dialog('widget'), + offsetAfter, + expected = box.offset(); + + testHelper.drag( element, '.ui-dialog-titlebar', -200, -200); // try to move out + offsetAfter = dlg.offset(); // should be the same + assert.deepEqual( offsetAfter, expected, "compare offset" ); +} ); + } ); From 6df435a37067c08b5af2786a4b794a2c529e5bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Tue, 7 Dec 2021 08:24:11 +0100 Subject: [PATCH 3/8] Update options.js --- tests/unit/dialog/options.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 0fa442fce94..3393cbd6e68 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -572,15 +572,15 @@ QUnit.test( "Open followed by close during show effect", function( assert ) { QUnit.test( "Dialog can't break out containment", function( assert ) { assert.expect( 1 ); var box = $( '
' ).css( { - height: '500px',border: '0px, margin:'0px', width:'500px', position: 'absolute', bottom: '0px', right: '0px', left: '50px', top: '50px' + height: '500px',border: '0px', margin:'0px', width:'500px', position: 'absolute', bottom: '0px', right: '0px', left: '50px', top: '50px' } ).appendTo( "body" ), element = $('
X
').dialog({containment: box, position: { at: "left top", of: box}}), // open on left top corner dlg = element.dialog('widget'), offsetAfter, expected = box.offset(); - testHelper.drag( element, '.ui-dialog-titlebar', -200, -200); // try to move out - offsetAfter = dlg.offset(); // should be the same + testHelper.drag( element, '.ui-dialog-titlebar', -200, -200); // try to move out + offsetAfter = dlg.offset(); // should be the same assert.deepEqual( offsetAfter, expected, "compare offset" ); } ); From dd037477d4b4fe41f6acd2d5dd1c4c48255228cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Tue, 7 Dec 2021 08:29:26 +0100 Subject: [PATCH 4/8] Update options.js adding cleaning up --- tests/unit/dialog/options.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 3393cbd6e68..425358f6217 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -579,9 +579,13 @@ QUnit.test( "Dialog can't break out containment", function( assert ) { offsetAfter, expected = box.offset(); - testHelper.drag( element, '.ui-dialog-titlebar', -200, -200); // try to move out + testHelper.drag( element, '.ui-dialog-titlebar', -200, -200); // try to move out offsetAfter = dlg.offset(); // should be the same assert.deepEqual( offsetAfter, expected, "compare offset" ); + setTimeout( function() { + element.dialog( "close" ); + box.remove(); + }, 100 ); } ); } ); From 335a3cc006f282f4c75ddac2999b10f80d8a62d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Mon, 10 Jan 2022 11:14:22 +0100 Subject: [PATCH 5/8] Update options.js --- tests/unit/dialog/options.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 425358f6217..2b5da41eff5 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -574,12 +574,12 @@ QUnit.test( "Dialog can't break out containment", function( assert ) { var box = $( '
' ).css( { height: '500px',border: '0px', margin:'0px', width:'500px', position: 'absolute', bottom: '0px', right: '0px', left: '50px', top: '50px' } ).appendTo( "body" ), - element = $('
X
').dialog({containment: box, position: { at: "left top", of: box}}), // open on left top corner - dlg = element.dialog('widget'), + element = $( '
X
' ).dialog( { containment: box, position: { at: "left top", of: box } } ), // open on left top corner + dlg = element.dialog( 'widget' ), offsetAfter, expected = box.offset(); - testHelper.drag( element, '.ui-dialog-titlebar', -200, -200); // try to move out + testHelper.drag( element, '.ui-dialog-titlebar', -200, -200 ); // try to move out offsetAfter = dlg.offset(); // should be the same assert.deepEqual( offsetAfter, expected, "compare offset" ); setTimeout( function() { From a38631fbe5a3312f007615db6497bd3ae8a9ce69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Mon, 10 Jan 2022 11:15:37 +0100 Subject: [PATCH 6/8] Update options.js --- tests/unit/dialog/options.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 2b5da41eff5..b76a57b3423 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -574,12 +574,12 @@ QUnit.test( "Dialog can't break out containment", function( assert ) { var box = $( '
' ).css( { height: '500px',border: '0px', margin:'0px', width:'500px', position: 'absolute', bottom: '0px', right: '0px', left: '50px', top: '50px' } ).appendTo( "body" ), - element = $( '
X
' ).dialog( { containment: box, position: { at: "left top", of: box } } ), // open on left top corner - dlg = element.dialog( 'widget' ), + element = $( "
X
" ).dialog( { containment: box, position: { at: "left top", of: box } } ), // open on left top corner + dlg = element.dialog( "widget" ), offsetAfter, expected = box.offset(); - testHelper.drag( element, '.ui-dialog-titlebar', -200, -200 ); // try to move out + testHelper.drag( element, ".ui-dialog-titlebar", -200, -200 ); // try to move out offsetAfter = dlg.offset(); // should be the same assert.deepEqual( offsetAfter, expected, "compare offset" ); setTimeout( function() { From a5751c6567fd68f17ffd6fd56cc135b96273be81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Mon, 10 Jan 2022 11:25:48 +0100 Subject: [PATCH 7/8] Update options.js --- tests/unit/dialog/options.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index b76a57b3423..280e9ebce10 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -578,14 +578,13 @@ QUnit.test( "Dialog can't break out containment", function( assert ) { dlg = element.dialog( "widget" ), offsetAfter, expected = box.offset(); - - testHelper.drag( element, ".ui-dialog-titlebar", -200, -200 ); // try to move out - offsetAfter = dlg.offset(); // should be the same - assert.deepEqual( offsetAfter, expected, "compare offset" ); - setTimeout( function() { - element.dialog( "close" ); - box.remove(); - }, 100 ); -} ); - + + testHelper.drag( element, ".ui-dialog-titlebar", -200, -200 ); // try to move out + offsetAfter = dlg.offset(); // should be the same + assert.deepEqual( offsetAfter, expected, "compare offset" ); + setTimeout( function() { + element.dialog( "close" ); + box.remove(); + }, 100 ); + } ); } ); From 6c6705238f073f39075ed403d2c88dd29287aa83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Gl=C3=BCck?= Date: Thu, 25 Aug 2022 09:36:08 +0200 Subject: [PATCH 8/8] Adding support for containment fixed GitHub Actions / Grunt based tests with Node.js 14.x --- tests/unit/dialog/options.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 280e9ebce10..17313e07796 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -571,8 +571,8 @@ QUnit.test( "Open followed by close during show effect", function( assert ) { QUnit.test( "Dialog can't break out containment", function( assert ) { assert.expect( 1 ); - var box = $( '
' ).css( { - height: '500px',border: '0px', margin:'0px', width:'500px', position: 'absolute', bottom: '0px', right: '0px', left: '50px', top: '50px' + var box = $( '
' ).css( { + height: "500px", border: "0px", margin: "0px", width: "500px", position: "absolute", bottom: "0px", right: "0px", left: "50px", top: "50px" } ).appendTo( "body" ), element = $( "
X
" ).dialog( { containment: box, position: { at: "left top", of: box } } ), // open on left top corner dlg = element.dialog( "widget" ),