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
|
|
|
|
|
|
|
el = $("<div></div>");
|
|
|
|
el.dialog({
|
|
|
|
open: function(ev, ui) {
|
2010-09-02 12:35:40 +00:00
|
|
|
ok(el.data("dialog")._isOpen, "interal _isOpen flag is set");
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(true, 'autoOpen: true fires open callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-04 03:39:19 +00:00
|
|
|
equals(ev.type, 'dialogopen', 'event type in callback');
|
|
|
|
same(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');
|
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-04 03:39:19 +00:00
|
|
|
equals(ev.type, 'dialogopen', 'event type in callback');
|
|
|
|
same(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) {
|
2010-09-02 12:35:40 +00:00
|
|
|
ok(el.data("dialog")._isOpen, "interal _isOpen flag is set");
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(true, 'dialog("open") fires open event');
|
|
|
|
equals(this, el[0], 'context of event');
|
2009-07-04 03:39:19 +00:00
|
|
|
same(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();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("dragStart", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(9);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2009-07-10 20:00:06 +00:00
|
|
|
el = $('<div></div>').dialog({
|
2009-02-04 04:35:18 +00:00
|
|
|
dragStart: function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dragStart callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-11 00:30:46 +00:00
|
|
|
equals(ev.type, 'dialogdragstart', 'event type in callback');
|
2010-03-11 20:48:21 +00:00
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-11 00:30:46 +00:00
|
|
|
}).bind('dialogdragstart', function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dialogdragstart event');
|
2009-07-10 20:00:06 +00:00
|
|
|
equals(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");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
var handle = $(".ui-dialog-titlebar", dlg());
|
|
|
|
drag(handle, 50, 50);
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("drag", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(9);
|
2009-07-10 20:00:06 +00:00
|
|
|
var hasDragged = false;
|
|
|
|
|
|
|
|
el = $('<div></div>').dialog({
|
2009-02-04 04:35:18 +00:00
|
|
|
drag: function(ev, ui) {
|
2009-07-10 20:00:06 +00:00
|
|
|
if (!hasDragged) {
|
|
|
|
ok(true, 'dragging fires drag callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
|
|
|
equals(ev.type, 'dialogdrag', 'event type in callback');
|
2010-03-11 20:48:21 +00:00
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
2009-07-10 20:00:06 +00:00
|
|
|
|
|
|
|
hasDragged = true;
|
|
|
|
}
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-10 20:00:06 +00:00
|
|
|
}).one('dialogdrag', function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dialogdrag event');
|
|
|
|
equals(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");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
var handle = $(".ui-dialog-titlebar", dlg());
|
|
|
|
drag(handle, 50, 50);
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("dragStop", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(9);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2009-07-10 20:00:06 +00:00
|
|
|
el = $('<div></div>').dialog({
|
2009-09-14 14:54:15 +00:00
|
|
|
dragStop: function(ev, ui) {
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(true, 'dragging fires dragStop callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-11 00:30:46 +00:00
|
|
|
equals(ev.type, 'dialogdragstop', 'event type in callback');
|
2010-03-11 20:48:21 +00:00
|
|
|
ok(ui.position !== undefined, "ui.position in callback");
|
|
|
|
ok(ui.offset !== undefined, "ui.offset in callback");
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-11 00:30:46 +00:00
|
|
|
}).bind('dialogdragstop', function(ev, ui) {
|
|
|
|
ok(true, 'dragging fires dialogdragstop event');
|
2009-07-10 20:00:06 +00:00
|
|
|
equals(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");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
var handle = $(".ui-dialog-titlebar", dlg());
|
|
|
|
drag(handle, 50, 50);
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resizeStart", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(13);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2009-07-10 20:00:06 +00:00
|
|
|
el = $('<div></div>').dialog({
|
2009-02-04 04:35:18 +00:00
|
|
|
resizeStart: function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires resizeStart callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-11 00:30:46 +00:00
|
|
|
equals(ev.type, 'dialogresizestart', 'event type in callback');
|
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");
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-11 00:30:46 +00:00
|
|
|
}).bind('dialogresizestart', function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires dialogresizestart event');
|
2009-07-10 20:00:06 +00:00
|
|
|
equals(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");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
var handle = $(".ui-resizable-se", dlg());
|
|
|
|
drag(handle, 50, 50);
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resize", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(13);
|
2009-07-10 20:00:06 +00:00
|
|
|
var hasResized = false;
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2009-07-10 20:00:06 +00:00
|
|
|
el = $('<div></div>').dialog({
|
2009-02-04 04:35:18 +00:00
|
|
|
resize: function(ev, ui) {
|
2009-07-10 20:00:06 +00:00
|
|
|
if (!hasResized) {
|
|
|
|
ok(true, 'resizing fires resize callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
|
|
|
equals(ev.type, 'dialogresize', 'event type in callback');
|
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");
|
2009-07-10 20:00:06 +00:00
|
|
|
|
|
|
|
hasResized = true;
|
|
|
|
}
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-10 20:00:06 +00:00
|
|
|
}).one('dialogresize', function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires dialogresize event');
|
|
|
|
equals(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");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
var handle = $(".ui-resizable-se", dlg());
|
|
|
|
drag(handle, 50, 50);
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("resizeStop", function() {
|
2010-03-11 20:48:21 +00:00
|
|
|
expect(13);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2009-07-10 20:00:06 +00:00
|
|
|
el = $('<div></div>').dialog({
|
2009-02-04 04:35:18 +00:00
|
|
|
resizeStop: function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires resizeStop callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-11 00:30:46 +00:00
|
|
|
equals(ev.type, 'dialogresizestop', 'event type in callback');
|
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");
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
2009-07-11 00:30:46 +00:00
|
|
|
}).bind('dialogresizestop', function(ev, ui) {
|
|
|
|
ok(true, 'resizing fires dialogresizestop event');
|
2009-07-10 20:00:06 +00:00
|
|
|
equals(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");
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
var handle = $(".ui-resizable-se", dlg());
|
|
|
|
drag(handle, 50, 50);
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("close", function() {
|
2009-07-04 03:39:19 +00:00
|
|
|
expect(7);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
|
|
|
el = $('<div></div>').dialog({
|
|
|
|
close: function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") fires close callback');
|
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-04 03:39:19 +00:00
|
|
|
equals(ev.type, 'dialogclose', 'event type in callback');
|
|
|
|
same(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');
|
|
|
|
equals(this, el[0], 'context of event');
|
2009-07-04 03:39:19 +00:00
|
|
|
same(ui, {}, 'ui hash in event');
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
el.dialog('close');
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
|
|
|
el = $('<div></div>').dialog({
|
2009-07-11 00:36:36 +00:00
|
|
|
beforeClose: function(ev, ui) {
|
|
|
|
ok(true, '.dialog("close") fires beforeClose callback');
|
2009-02-04 04:35:18 +00:00
|
|
|
equals(this, el[0], "context of callback");
|
2009-07-04 03:39:19 +00:00
|
|
|
equals(ev.type, 'dialogbeforeclose', 'event type in callback');
|
|
|
|
same(ui, {}, 'ui hash in callback');
|
2009-02-04 04:35:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
el.dialog('close');
|
2009-07-11 00:36:36 +00:00
|
|
|
isOpen('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');
|
|
|
|
equals(this, el[0], "context of callback");
|
|
|
|
equals(ev.type, 'dialogbeforeclose', 'event type in callback');
|
|
|
|
same(ui, {}, 'ui hash in callback');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
el.dialog('close');
|
|
|
|
isOpen('beforeClose callback should prevent dialog from closing');
|
|
|
|
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');
|
|
|
|
equals(this, el[0], "context of event");
|
2009-07-04 03:39:19 +00:00
|
|
|
same(ui, {}, 'ui hash in event');
|
2009-02-04 04:35:18 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
el.dialog('close');
|
|
|
|
isOpen('dialogbeforeclose event should prevent dialog from closing');
|
|
|
|
el.remove();
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|