2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* dialog_core.js
|
|
|
|
*/
|
2009-02-04 04:35:18 +00:00
|
|
|
|
|
|
|
var el,
|
|
|
|
offsetBefore, offsetAfter,
|
|
|
|
heightBefore, heightAfter,
|
|
|
|
widthBefore, widthAfter,
|
|
|
|
dragged;
|
|
|
|
|
|
|
|
function dlg() {
|
2010-02-25 11:09:39 +00:00
|
|
|
return el.dialog('widget');
|
2009-02-04 04:35:18 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.isOpen = function(why) {
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(dlg().is(":visible"), why);
|
2012-10-23 14:36:42 +00:00
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.isNotOpen = function(why) {
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(!dlg().is(":visible"), why);
|
2012-10-23 14:36:42 +00:00
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
|
|
|
function drag(handle, dx, dy) {
|
|
|
|
var d = dlg();
|
|
|
|
offsetBefore = d.offset();
|
|
|
|
heightBefore = d.height();
|
|
|
|
widthBefore = d.width();
|
|
|
|
//this mouseover is to work around a limitation in resizable
|
|
|
|
//TODO: fix resizable so handle doesn't require mouseover in order to be used
|
|
|
|
$(handle, d).simulate("mouseover");
|
|
|
|
$(handle, d).simulate("drag", {
|
|
|
|
dx: dx || 0,
|
|
|
|
dy: dy || 0
|
|
|
|
});
|
|
|
|
dragged = { dx: dx, dy: dy };
|
|
|
|
offsetAfter = d.offset();
|
|
|
|
heightAfter = d.height();
|
|
|
|
widthAfter = d.width();
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.dialogMoved = function(dx, dy, msg) {
|
2009-02-04 04:35:18 +00:00
|
|
|
msg = msg ? msg + "." : "";
|
2012-04-19 14:27:06 +00:00
|
|
|
var actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) },
|
|
|
|
expected = { left: Math.round(offsetBefore.left + dx), top: Math.round(offsetBefore.top + dy) };
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
2012-10-23 14:36:42 +00:00
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.shouldmove = function(why) {
|
2009-02-04 04:35:18 +00:00
|
|
|
var handle = $(".ui-dialog-titlebar", dlg());
|
2009-09-19 10:16:08 +00:00
|
|
|
drag(handle, 50, -50);
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.dialogMoved(50, -50, why);
|
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.shouldnotmove = function(why) {
|
2009-02-04 04:35:18 +00:00
|
|
|
var handle = $(".ui-dialog-titlebar", dlg());
|
2009-09-19 10:16:08 +00:00
|
|
|
drag(handle, 50, -50);
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.dialogMoved(0, 0, why);
|
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.resized = function(dw, dh, msg) {
|
2009-02-04 04:35:18 +00:00
|
|
|
msg = msg ? msg + "." : "";
|
2012-04-19 14:27:06 +00:00
|
|
|
var actual = { width: widthAfter, height: heightAfter },
|
|
|
|
expected = { width: widthBefore + dw, height: heightBefore + dh };
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
2012-10-23 14:36:42 +00:00
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.shouldresize = function(why) {
|
2009-02-04 04:35:18 +00:00
|
|
|
var handle = $(".ui-resizable-se", dlg());
|
|
|
|
drag(handle, 50, 50);
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.resized(50, 50, why);
|
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.shouldnotresize = function(why) {
|
2009-02-04 04:35:18 +00:00
|
|
|
var handle = $(".ui-resizable-se", dlg());
|
|
|
|
drag(handle, 50, 50);
|
2012-10-23 14:36:42 +00:00
|
|
|
TestHelpers.resized(0, 0, why);
|
|
|
|
};
|
2009-02-04 04:35:18 +00:00
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
module("dialog: core");
|
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
test("title id", function() {
|
2012-05-30 04:11:42 +00:00
|
|
|
expect(1);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
|
|
|
el = $('<div></div>').dialog();
|
2012-05-30 04:11:42 +00:00
|
|
|
var titleId = dlg().find('.ui-dialog-title').attr('id');
|
|
|
|
ok( /ui-id-\d+$/.test( titleId ), 'auto-numbered title id');
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("ARIA", function() {
|
|
|
|
expect(4);
|
|
|
|
|
|
|
|
el = $('<div></div>').dialog();
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dlg().attr('role'), 'dialog', 'dialog role');
|
2009-02-04 04:35:18 +00:00
|
|
|
|
|
|
|
var labelledBy = dlg().attr('aria-labelledby');
|
|
|
|
ok(labelledBy.length > 0, 'has aria-labelledby attribute');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dlg().find('.ui-dialog-title').attr('id'), labelledBy,
|
2009-02-04 04:35:18 +00:00
|
|
|
'proper aria-labelledby attribute');
|
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(dlg().find('.ui-dialog-titlebar-close').attr('role'), 'button',
|
2009-02-04 04:35:18 +00:00
|
|
|
'close link role');
|
|
|
|
|
|
|
|
el.remove();
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
test("widget method", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 1 );
|
2011-08-04 01:43:52 +00:00
|
|
|
var dialog = $("<div>").appendTo("#main").dialog();
|
2012-02-28 14:56:32 +00:00
|
|
|
deepEqual(dialog.parent()[0], dialog.dialog("widget")[0]);
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|