2015-04-07 00:23:50 +00:00
|
|
|
define( [
|
2016-04-03 16:10:09 +00:00
|
|
|
"qunit",
|
2015-04-07 00:23:50 +00:00
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 01:59:10 +00:00
|
|
|
"ui/widgets/dialog"
|
2016-04-03 16:10:09 +00:00
|
|
|
], function( QUnit, $, testHelper ) {
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "dialog: events", { afterEach: testHelper.moduleAfterEach } );
|
2015-08-24 12:59:54 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "open", function( assert ) {
|
|
|
|
assert.expect( 13 );
|
2015-08-24 12:59:54 +00:00
|
|
|
|
|
|
|
var element = $( "<div></div>" );
|
|
|
|
element.dialog( {
|
|
|
|
open: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" );
|
|
|
|
assert.ok( true, "autoOpen: true fires open callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogopen", "event type in callback" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in callback" );
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" );
|
|
|
|
element.dialog( {
|
2009-02-04 04:35:18 +00:00
|
|
|
autoOpen: false,
|
2015-08-24 12:59:54 +00:00
|
|
|
open: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('open') fires open callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogopen", "event type in callback" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in callback" );
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).on( "dialogopen", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" );
|
|
|
|
assert.ok( true, "dialog('open') fires open event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in event" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
element.dialog( "open" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "focus", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2013-01-31 05:38:20 +00:00
|
|
|
var element, other;
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "#dialog1" ).dialog( {
|
2012-11-09 17:44:29 +00:00
|
|
|
autoOpen: false
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
other = $( "#dialog2" ).dialog( {
|
2012-11-09 17:44:29 +00:00
|
|
|
autoOpen: false
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-11-09 17:44:29 +00:00
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element.one( "dialogopen", function() {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "open, just once" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.one( "dialogfocus", function() {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "focus on open" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-11-09 17:44:29 +00:00
|
|
|
other.dialog( "open" );
|
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element.one( "dialogfocus", function() {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "when opening and already open and wasn't on top" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-11-09 17:44:29 +00:00
|
|
|
other.dialog( "open" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "open" );
|
2012-11-09 17:44:29 +00:00
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element.one( "dialogfocus", function() {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "when calling moveToTop and wasn't on top" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-11-09 17:44:29 +00:00
|
|
|
other.dialog( "moveToTop" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "moveToTop" );
|
2012-11-09 17:44:29 +00:00
|
|
|
|
2015-05-14 01:57:04 +00:00
|
|
|
element.on( "dialogfocus", function() {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "when mousedown anywhere on the dialog and it wasn't on top" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-11-09 17:44:29 +00:00
|
|
|
other.dialog( "moveToTop" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.trigger( "mousedown" );
|
2012-11-09 17:44:29 +00:00
|
|
|
|
2015-08-21 04:11:21 +00:00
|
|
|
// Triggers just once when already on top
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "open" );
|
|
|
|
element.dialog( "moveToTop" );
|
|
|
|
element.trigger( "mousedown" );
|
2012-11-09 17:44:29 +00:00
|
|
|
|
2013-01-31 05:38:20 +00:00
|
|
|
element.add( other ).remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-11-09 17:44:29 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "dragStart", function( assert ) {
|
|
|
|
assert.expect( 9 );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog( {
|
|
|
|
dragStart: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "dragging fires dragStart callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogdragstart", "event type in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.offset !== undefined, "ui.offset in callback" );
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).on( "dialogdragstart", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "dragging fires dialogdragstart event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.offset !== undefined, "ui.offset in callback" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) );
|
|
|
|
testHelper.drag( element, handle, 50, 50 );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "drag", function( assert ) {
|
|
|
|
assert.expect( 9 );
|
2012-04-19 14:27:06 +00:00
|
|
|
var handle,
|
2012-11-03 20:17:16 +00:00
|
|
|
hasDragged = false,
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog( {
|
|
|
|
drag: function( ev, ui ) {
|
|
|
|
if ( !hasDragged ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "dragging fires drag callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogdrag", "event type in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.offset !== undefined, "ui.offset in callback" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
hasDragged = true;
|
|
|
|
}
|
2009-07-10 20:00:06 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).one( "dialogdrag", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "dragging fires dialogdrag event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.offset !== undefined, "ui.offset in callback" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) );
|
|
|
|
testHelper.drag( element, handle, 50, 50 );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "dragStop", function( assert ) {
|
|
|
|
assert.expect( 9 );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog( {
|
|
|
|
dragStop: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "dragging fires dragStop callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogdragstop", "event type in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.offset !== undefined, "ui.offset in callback" );
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).on( "dialogdragstop", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "dragging fires dialogdragstop event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.offset !== undefined, "ui.offset in callback" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) );
|
|
|
|
testHelper.drag( element, handle, 50, 50 );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "resizeStart", function( assert ) {
|
|
|
|
assert.expect( 13 );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog( {
|
|
|
|
resizeStart: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "resizing fires resizeStart callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogresizestart", "event type in callback" );
|
|
|
|
assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
|
|
|
|
assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.size !== undefined, "ui.size in callback" );
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).on( "dialogresizestart", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "resizing fires dialogresizestart event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
|
|
|
|
assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.size !== undefined, "ui.size in callback" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
handle = $( ".ui-resizable-se", element.dialog( "widget" ) );
|
|
|
|
testHelper.drag( element, handle, 50, 50 );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "resize", function( assert ) {
|
|
|
|
assert.expect( 13 );
|
2012-04-19 14:27:06 +00:00
|
|
|
var handle,
|
2012-11-03 20:17:16 +00:00
|
|
|
hasResized = false,
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog( {
|
|
|
|
resize: function( ev, ui ) {
|
|
|
|
if ( !hasResized ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "resizing fires resize callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogresize", "event type in callback" );
|
|
|
|
assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
|
|
|
|
assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.size !== undefined, "ui.size in callback" );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
hasResized = true;
|
|
|
|
}
|
2009-07-10 20:00:06 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).one( "dialogresize", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "resizing fires dialogresize event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
|
|
|
|
assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.size !== undefined, "ui.size in callback" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
handle = $( ".ui-resizable-se", element.dialog( "widget" ) );
|
|
|
|
testHelper.drag( element, handle, 50, 50 );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "resizeStop", function( assert ) {
|
|
|
|
assert.expect( 13 );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog( {
|
|
|
|
resizeStop: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "resizing fires resizeStop callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogresizestop", "event type in callback" );
|
|
|
|
assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
|
|
|
|
assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.size !== undefined, "ui.size in callback" );
|
2012-11-03 20:17:16 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).on( "dialogresizestop", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, "resizing fires dialogresizestop event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" );
|
|
|
|
assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" );
|
|
|
|
assert.ok( ui.position !== undefined, "ui.position in callback" );
|
|
|
|
assert.ok( ui.size !== undefined, "ui.size in callback" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
handle = $( ".ui-resizable-se", element.dialog( "widget" ) );
|
|
|
|
testHelper.drag( element, handle, 50, 50 );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "close", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 14 );
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2015-08-24 12:59:54 +00:00
|
|
|
var element = $( "<div></div>" ).dialog( {
|
|
|
|
close: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('close') fires close callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogclose", "event type in callback" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in callback" );
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).on( "dialogclose", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('close') fires dialogclose event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in event" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
element.dialog( "close" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2012-10-17 13:28:51 +00:00
|
|
|
|
|
|
|
// Close event with an effect
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog( {
|
2012-10-17 13:28:51 +00:00
|
|
|
hide: 10,
|
2015-08-24 12:59:54 +00:00
|
|
|
close: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('close') fires close callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogclose", "event type in callback" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in callback" );
|
|
|
|
ready();
|
2012-10-17 13:28:51 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} ).on( "dialogclose", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('close') fires dialogclose event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in event" );
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
element.dialog( "close" );
|
|
|
|
} );
|
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "beforeClose", function( assert ) {
|
|
|
|
assert.expect( 14 );
|
2015-08-24 12:59:54 +00:00
|
|
|
|
|
|
|
var element = $( "<div></div>" ).dialog( {
|
|
|
|
beforeClose: function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('close') fires beforeClose callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogbeforeclose", "event type in callback" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in callback" );
|
2009-02-04 04:35:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2015-08-24 12:59:54 +00:00
|
|
|
element.dialog( "close" );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog();
|
|
|
|
element.dialog( "option", "beforeClose", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('close') fires beforeClose callback" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of callback" );
|
|
|
|
assert.equal( ev.type, "dialogbeforeclose", "event type in callback" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in callback" );
|
2010-01-27 10:31:17 +00:00
|
|
|
return false;
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
element.dialog( "close" );
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2010-01-27 10:31:17 +00:00
|
|
|
|
2015-08-24 12:59:54 +00:00
|
|
|
element = $( "<div></div>" ).dialog().on( "dialogbeforeclose", function( ev, ui ) {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( true, ".dialog('close') triggers dialogbeforeclose event" );
|
|
|
|
assert.equal( this, element[ 0 ], "context of event" );
|
|
|
|
assert.deepEqual( ui, {}, "ui hash in event" );
|
2009-02-04 04:35:18 +00:00
|
|
|
return false;
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
element.dialog( "close" );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( element.dialog( "widget" ).is( ":visible" ), "dialogbeforeclose event should prevent dialog from closing" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2012-11-25 05:18:51 +00:00
|
|
|
// #8789 and #8838
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "ensure dialog's container doesn't scroll on resize and focus", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2015-08-24 12:59:54 +00:00
|
|
|
|
|
|
|
var element = $( "#dialog1" ).dialog(),
|
|
|
|
initialScroll = $( window ).scrollTop();
|
|
|
|
element.dialog( "option", "height", 600 );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after height change" );
|
2015-08-24 12:59:54 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
$( ".ui-dialog-titlebar-close" ).simulate( "mousedown" );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog" );
|
2015-08-24 12:59:54 +00:00
|
|
|
element.dialog( "destroy" );
|
2016-04-03 16:10:09 +00:00
|
|
|
ready();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-11-25 05:18:51 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "#5184: isOpen in dialogclose event is true", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
2015-08-24 12:59:54 +00:00
|
|
|
var element = $( "<div></div>" ).dialog( {
|
2012-12-08 01:06:29 +00:00
|
|
|
close: function() {
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( !element.dialog( "isOpen" ), "dialog is not open during close" );
|
2012-12-08 01:06:29 +00:00
|
|
|
}
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( element.dialog( "isOpen" ), "dialog is open after init" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.dialog( "close" );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.ok( !element.dialog( "isOpen" ), "dialog is not open after close" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2012-12-08 01:06:29 +00:00
|
|
|
|
2016-04-03 16:10:09 +00:00
|
|
|
QUnit.test( "ensure dialog keeps focus when clicking modal overlay", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-01-31 05:17:45 +00:00
|
|
|
|
2015-08-24 12:59:54 +00:00
|
|
|
var element = $( "<div></div>" ).dialog( {
|
2013-01-31 05:17:45 +00:00
|
|
|
modal: true
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is in dialog" );
|
2015-08-24 12:59:54 +00:00
|
|
|
$( ".ui-widget-overlay" ).simulate( "mousedown" );
|
2016-04-03 16:10:09 +00:00
|
|
|
assert.equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is still in dialog" );
|
2013-01-31 05:38:20 +00:00
|
|
|
element.remove();
|
2015-08-24 12:59:54 +00:00
|
|
|
} );
|
2013-01-31 05:17:45 +00:00
|
|
|
|
2015-04-07 00:23:50 +00:00
|
|
|
} );
|