2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* dialog_events.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
module("dialog: events");
|
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
test("open", function() {
|
2010-09-02 12:35:40 +00:00
|
|
|
expect(13);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var el = $("<div></div>");
|
2009-02-04 04:35:18 +00:00
|
|
|
el.dialog({
|
|
|
|
open: function(ev, ui) {
|
2012-11-09 18:28:13 +00:00
|
|
|
ok(el.data("ui-dialog")._isOpen, "interal _isOpen flag is set");
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(true, 'autoOpen: true fires open callback');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogopen', 'event type in callback');
|
|
|
|
deepEqual(ui, {}, 'ui hash in callback');
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
el.remove();
|
|
|
|
|
|
|
|
el = $("<div></div>");
|
|
|
|
el.dialog({
|
|
|
|
autoOpen: false,
|
|
|
|
open: function(ev, ui) {
|
|
|
|
ok(true, '.dialog("open") fires open callback');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogopen', 'event type in callback');
|
|
|
|
deepEqual(ui, {}, 'ui hash in callback');
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-04 03:39:19 +00:00
|
|
|
}).bind('dialogopen', function(ev, ui) {
|
2012-11-09 18:28:13 +00:00
|
|
|
ok(el.data("ui-dialog")._isOpen, "interal _isOpen flag is set");
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(true, 'dialog("open") fires open event');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], 'context of event');
|
|
|
|
deepEqual(ui, {}, 'ui hash in event');
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
2009-07-04 03:39:19 +00:00
|
|
|
el.dialog("open");
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
2012-11-09 17:44:29 +00:00
|
|
|
|
|
|
|
test( "focus", function() {
|
|
|
|
expect( 5 );
|
|
|
|
var el, other;
|
|
|
|
el = $("#dialog1").dialog({
|
|
|
|
autoOpen: false
|
|
|
|
});
|
|
|
|
other = $("#dialog2").dialog({
|
|
|
|
autoOpen: false
|
|
|
|
});
|
|
|
|
|
|
|
|
el.one( "dialogopen", function() {
|
|
|
|
ok( true, "open, just once" );
|
|
|
|
});
|
|
|
|
el.one( "dialogfocus", function() {
|
|
|
|
ok( true, "focus on open" );
|
|
|
|
});
|
|
|
|
other.dialog( "open" );
|
|
|
|
|
|
|
|
el.one( "dialogfocus", function() {
|
|
|
|
ok( true, "when opening and already open and wasn't on top" );
|
|
|
|
});
|
|
|
|
other.dialog( "open" );
|
|
|
|
el.dialog( "open" );
|
|
|
|
|
|
|
|
el.one( "dialogfocus", function() {
|
|
|
|
ok( true, "when calling moveToTop and wasn't on top" );
|
|
|
|
});
|
|
|
|
other.dialog( "moveToTop" );
|
|
|
|
el.dialog( "moveToTop" );
|
|
|
|
|
|
|
|
el.bind( "dialogfocus", function() {
|
|
|
|
ok( true, "when mousedown anywhere on the dialog and it wasn't on top" );
|
|
|
|
});
|
|
|
|
other.dialog( "moveToTop" );
|
|
|
|
el.trigger( "mousedown" );
|
|
|
|
|
|
|
|
// triggers just once when already on top
|
|
|
|
el.dialog( "open" );
|
|
|
|
el.dialog( "moveToTop" );
|
|
|
|
el.trigger( "mousedown" );
|
|
|
|
|
|
|
|
el.add( other ).remove();
|
|
|
|
});
|
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
test("dragStart", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(9);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
dragStart: function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dragStart callback');
|
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogdragstart', 'event type in callback');
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
|
|
|
}
|
|
|
|
}).bind('dialogdragstart', function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dialogdragstart event');
|
|
|
|
equal(this, el[0], 'context of event');
|
2010-03-11 20:48:21 +00:00
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
2012-11-03 20:17:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
handle = $(".ui-dialog-titlebar", el.dialog('widget'));
|
|
|
|
TestHelpers.dialog.drag(el, handle, 50, 50);
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("drag", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(9);
|
2012-04-19 14:27:06 +00:00
|
|
|
var handle,
|
2012-11-03 20:17:16 +00:00
|
|
|
hasDragged = false,
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
drag: function(ev, ui) {
|
|
|
|
if (!hasDragged) {
|
|
|
|
ok(true, 'dragging fires drag callback');
|
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogdrag', 'event type in callback');
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
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
|
|
|
}
|
2012-11-03 20:17:16 +00:00
|
|
|
}).one('dialogdrag', function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dialogdrag event');
|
|
|
|
equal(this, el[0], 'context of event');
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
|
|
|
});
|
|
|
|
|
|
|
|
handle = $(".ui-dialog-titlebar", el.dialog('widget'));
|
|
|
|
TestHelpers.dialog.drag(el, handle, 50, 50);
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("dragStop", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(9);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
dragStop: function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dragStop callback');
|
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogdragstop', 'event type in callback');
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
|
|
|
}
|
|
|
|
}).bind('dialogdragstop', function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dialogdragstop event');
|
|
|
|
equal(this, el[0], 'context of event');
|
2010-03-11 20:48:21 +00:00
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
2012-11-03 20:17:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
handle = $(".ui-dialog-titlebar", el.dialog('widget'));
|
|
|
|
TestHelpers.dialog.drag(el, handle, 50, 50);
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resizeStart", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(13);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
resizeStart: function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires resizeStart callback');
|
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogresizestart', 'event type in callback');
|
|
|
|
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
|
|
|
|
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.size !== undefined, "ui.size in callback");
|
|
|
|
}
|
|
|
|
}).bind('dialogresizestart', function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires dialogresizestart event');
|
|
|
|
equal(this, el[0], 'context of event');
|
2010-03-11 20:48:21 +00:00
|
|
|
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
|
|
|
|
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.size !== undefined, "ui.size in callback");
|
2012-11-03 20:17:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
handle = $(".ui-resizable-se", el.dialog('widget'));
|
|
|
|
TestHelpers.dialog.drag(el, handle, 50, 50);
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resize", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(13);
|
2012-04-19 14:27:06 +00:00
|
|
|
var handle,
|
2012-11-03 20:17:16 +00:00
|
|
|
hasResized = false,
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
resize: function(ev, ui) {
|
|
|
|
if (!hasResized) {
|
|
|
|
ok(true, 'resizing fires resize callback');
|
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogresize', 'event type in callback');
|
|
|
|
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
|
|
|
|
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
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
|
|
|
}
|
2012-11-03 20:17:16 +00:00
|
|
|
}).one('dialogresize', function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires dialogresize event');
|
|
|
|
equal(this, el[0], 'context of event');
|
|
|
|
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
|
|
|
|
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.size !== undefined, "ui.size in callback");
|
|
|
|
});
|
|
|
|
|
|
|
|
handle = $(".ui-resizable-se", el.dialog('widget'));
|
|
|
|
TestHelpers.dialog.drag(el, handle, 50, 50);
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resizeStop", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(13);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var handle,
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
resizeStop: function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires resizeStop callback');
|
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogresizestop', 'event type in callback');
|
|
|
|
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
|
|
|
|
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.size !== undefined, "ui.size in callback");
|
|
|
|
}
|
|
|
|
}).bind('dialogresizestop', function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires dialogresizestop event');
|
|
|
|
equal(this, el[0], 'context of event');
|
|
|
|
ok(ui.originalPosition !== undefined, "ui.originalPosition in callback");
|
|
|
|
ok(ui.originalSize !== undefined, "ui.originalSize in callback");
|
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.size !== undefined, "ui.size in callback");
|
|
|
|
});
|
|
|
|
|
|
|
|
handle = $(".ui-resizable-se", el.dialog('widget'));
|
|
|
|
TestHelpers.dialog.drag(el, handle, 50, 50);
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
2012-10-17 13:28:51 +00:00
|
|
|
asyncTest("close", function() {
|
|
|
|
expect(14);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var el = $('<div></div>').dialog({
|
2009-02-04 04:35:18 +00:00
|
|
|
close: function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") fires close callback');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogclose', 'event type in callback');
|
|
|
|
deepEqual(ui, {}, 'ui hash in callback');
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-04 03:39:19 +00:00
|
|
|
}).bind('dialogclose', function(ev, ui) {
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(true, '.dialog("close") fires dialogclose event');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], 'context of event');
|
|
|
|
deepEqual(ui, {}, 'ui hash in event');
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
el.dialog('close');
|
|
|
|
el.remove();
|
2012-10-17 13:28:51 +00:00
|
|
|
|
|
|
|
// Close event with an effect
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
hide: 10,
|
|
|
|
close: function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") fires close callback');
|
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogclose', 'event type in callback');
|
|
|
|
deepEqual(ui, {}, 'ui hash in callback');
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
}).bind('dialogclose', function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") fires dialogclose event');
|
|
|
|
equal(this, el[0], 'context of event');
|
|
|
|
deepEqual(ui, {}, 'ui hash in event');
|
|
|
|
});
|
|
|
|
el.dialog('close');
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
|
2009-07-11 00:36:36 +00:00
|
|
|
test("beforeClose", function() {
|
2010-01-27 10:31:17 +00:00
|
|
|
expect(14);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var el = $('<div></div>').dialog({
|
2009-07-11 00:36:36 +00:00
|
|
|
beforeClose: function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") fires beforeClose callback');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogbeforeclose', 'event type in callback');
|
|
|
|
deepEqual(ui, {}, 'ui hash in callback');
|
2009-02-04 04:35:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-11-03 20:17:16 +00:00
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
el.dialog('close');
|
2012-11-03 20:17:16 +00:00
|
|
|
ok( el.dialog("widget").is(":visible"), 'beforeClose callback should prevent dialog from closing');
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
|
2010-01-27 10:31:17 +00:00
|
|
|
el = $('<div></div>').dialog();
|
|
|
|
el.dialog('option', 'beforeClose', function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") fires beforeClose callback');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], "context of callback");
|
|
|
|
equal(ev.type, 'dialogbeforeclose', 'event type in callback');
|
|
|
|
deepEqual(ui, {}, 'ui hash in callback');
|
2010-01-27 10:31:17 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
el.dialog('close');
|
2012-11-03 20:17:16 +00:00
|
|
|
|
|
|
|
ok( el.dialog("widget").is(":visible"), 'beforeClose callback should prevent dialog from closing');
|
2010-01-27 10:31:17 +00:00
|
|
|
el.remove();
|
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
el = $('<div></div>').dialog().bind('dialogbeforeclose', function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") triggers dialogbeforeclose event');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(this, el[0], "context of event");
|
|
|
|
deepEqual(ui, {}, 'ui hash in event');
|
2009-02-04 04:35:18 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
el.dialog('close');
|
2012-11-03 20:17:16 +00:00
|
|
|
ok( el.dialog("widget").is(":visible"), 'dialogbeforeclose event should prevent dialog from closing');
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2012-11-25 05:18:51 +00:00
|
|
|
// #8789 and #8838
|
|
|
|
asyncTest("ensure dialog's container doesn't scroll on resize and focus", function() {
|
|
|
|
expect(2);
|
|
|
|
|
|
|
|
var el = $('#dialog1').dialog(),
|
|
|
|
initialScroll = $(window).scrollTop();
|
|
|
|
el.dialog('option', 'height', 600);
|
|
|
|
equal($(window).scrollTop(), initialScroll, "scroll hasn't moved after height change");
|
|
|
|
setTimeout( function(){
|
|
|
|
$(".ui-dialog-titlebar-close").simulate('mousedown');
|
|
|
|
equal($(window).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog");
|
|
|
|
el.dialog('destroy');
|
|
|
|
start();
|
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
|
2012-12-08 01:06:29 +00:00
|
|
|
test("#5184: isOpen in dialogclose event is true", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
var el = $( "<div></div>" ).dialog({
|
|
|
|
close: function() {
|
|
|
|
ok( !el.dialog("isOpen"), "dialog is not open during close" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ok( el.dialog("isOpen"), "dialog is open after init" );
|
|
|
|
el.dialog( "close" );
|
|
|
|
ok( !el.dialog("isOpen"), "dialog is not open after close" );
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|