2008-06-06 03:58:15 +00:00
|
|
|
/*
|
2008-06-07 06:09:04 +00:00
|
|
|
* draggable unit tests
|
2008-06-06 03:58:15 +00:00
|
|
|
*/
|
2008-06-09 05:59:18 +00:00
|
|
|
(function($) {
|
2008-06-07 17:18:40 +00:00
|
|
|
//
|
|
|
|
// Draggable Test Helper Functions
|
|
|
|
//
|
2008-11-12 02:52:31 +00:00
|
|
|
|
|
|
|
var defaults = {
|
|
|
|
appendTo: "parent",
|
|
|
|
axis: false,
|
|
|
|
cancel: ":input",
|
|
|
|
connectToSortable: false,
|
|
|
|
containment: false,
|
|
|
|
cursor: "default",
|
|
|
|
cursorAt: null,
|
|
|
|
delay: 0,
|
|
|
|
disabled: false,
|
|
|
|
distance: 1,
|
|
|
|
grid: false,
|
|
|
|
handle: false,
|
|
|
|
helper: "original",
|
|
|
|
iframeFix: false,
|
|
|
|
opacity: 1.0,
|
|
|
|
refreshPositions: false,
|
|
|
|
revert: false,
|
|
|
|
revertDuration: 500,
|
|
|
|
scroll: false,
|
|
|
|
scrollSensitivity: 20,
|
|
|
|
scrollSpeed: 20,
|
|
|
|
scope: "default",
|
|
|
|
snap: false,
|
|
|
|
snapMode: "both",
|
|
|
|
snapTolerance: 20,
|
|
|
|
stack: false,
|
|
|
|
zIndex: null
|
|
|
|
};
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
var el, offsetBefore, offsetAfter, dragged;
|
|
|
|
|
|
|
|
var drag = function(handle, dx, dy) {
|
|
|
|
var element = el.data("draggable").element;
|
|
|
|
offsetBefore = el.offset();
|
|
|
|
$(handle).simulate("drag", {
|
|
|
|
dx: dx || 0,
|
|
|
|
dy: dy || 0
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2008-06-07 06:09:04 +00:00
|
|
|
dragged = { dx: dx, dy: dy };
|
|
|
|
offsetAfter = el.offset();
|
|
|
|
}
|
|
|
|
|
|
|
|
var moved = function (dx, dy, msg) {
|
|
|
|
msg = msg ? msg + "." : "";
|
|
|
|
var actual = { left: offsetAfter.left, top: offsetAfter.top };
|
2008-06-21 13:54:41 +00:00
|
|
|
var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy };
|
2008-10-13 21:32:42 +00:00
|
|
|
same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);
|
2008-06-07 06:09:04 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 17:18:40 +00:00
|
|
|
function shouldmove(why) {
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50, why);
|
|
|
|
}
|
|
|
|
|
|
|
|
function shouldnotmove(why) {
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(0, 0, why);
|
|
|
|
}
|
|
|
|
|
2008-06-06 06:34:09 +00:00
|
|
|
var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }
|
2008-06-07 06:09:04 +00:00
|
|
|
|
2008-06-06 06:34:09 +00:00
|
|
|
var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }
|
|
|
|
|
2008-06-07 17:18:40 +00:00
|
|
|
// Draggable Tests
|
2008-06-07 18:03:19 +00:00
|
|
|
module("draggable");
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 17:18:40 +00:00
|
|
|
test("init", function() {
|
|
|
|
expect(6);
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").appendTo('body').draggable().remove();
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, '.draggable() called on element');
|
|
|
|
|
|
|
|
$([]).draggable();
|
|
|
|
ok(true, '.draggable() called on empty collection');
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable();
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, '.draggable() called on disconnected DOMElement');
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable().draggable("foo");
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, 'arbitrary method called after init');
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable().data("foo.draggable");
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, 'arbitrary option getter after init');
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable().data("foo.draggable", "bar");
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, 'arbitrary option setter after init');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("destroy", function() {
|
|
|
|
expect(6);
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").appendTo('body').draggable().draggable("destroy").remove();
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, '.draggable("destroy") called on element');
|
|
|
|
|
|
|
|
$([]).draggable().draggable("destroy");
|
|
|
|
ok(true, '.draggable("destroy") called on empty collection');
|
2008-06-07 06:09:04 +00:00
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable().draggable("destroy");
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, '.draggable("destroy") called on disconnected DOMElement');
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable().draggable("destroy").draggable("foo");
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, 'arbitrary method called after destroy');
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable().draggable("destroy").data("foo.draggable");
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, 'arbitrary option getter after destroy');
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
$("<div></div>").draggable().draggable("destroy").data("foo.draggable", "bar");
|
2008-06-07 17:18:40 +00:00
|
|
|
ok(true, 'arbitrary option setter after destroy');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("enable", function() {
|
|
|
|
expect(6);
|
|
|
|
el = $("#draggable2").draggable({ disabled: true });
|
|
|
|
shouldnotmove('.draggable({ disabled: true })');
|
|
|
|
el.draggable("enable");
|
|
|
|
shouldmove('.draggable("enable")');
|
|
|
|
equals(el.data("disabled.draggable"), false, "disabled.draggable getter");
|
|
|
|
|
|
|
|
el.draggable("destroy");
|
|
|
|
el.draggable({ disabled: true });
|
|
|
|
shouldnotmove('.draggable({ disabled: true })');
|
|
|
|
el.data("disabled.draggable", false);
|
|
|
|
equals(el.data("disabled.draggable"), false, "disabled.draggable setter");
|
|
|
|
shouldmove('.data("disabled.draggable", false)');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("disable", function() {
|
|
|
|
expect(6);
|
|
|
|
el = $("#draggable2").draggable({ disabled: false });
|
|
|
|
shouldmove('.draggable({ disabled: false })');
|
|
|
|
el.draggable("disable");
|
|
|
|
shouldnotmove('.draggable("disable")');
|
|
|
|
equals(el.data("disabled.draggable"), true, "disabled.draggable getter");
|
|
|
|
|
|
|
|
el.draggable("destroy");
|
|
|
|
|
|
|
|
el.draggable({ disabled: false });
|
|
|
|
shouldmove('.draggable({ disabled: false })');
|
|
|
|
el.data("disabled.draggable", true);
|
|
|
|
equals(el.data("disabled.draggable"), true, "disabled.draggable setter");
|
|
|
|
shouldnotmove('.data("disabled.draggable", true)');
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("element types", function() {
|
|
|
|
var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'
|
|
|
|
+ ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'
|
|
|
|
+ ',acronym,code,samp,kbd,var,img,object,hr'
|
|
|
|
+ ',input,button,label,select,iframe').split(',');
|
|
|
|
|
|
|
|
$.each(typeNames, function(i) {
|
|
|
|
var typeName = typeNames[i];
|
|
|
|
el = $(document.createElement(typeName)).appendTo('body');
|
|
|
|
(typeName == 'table' && el.append("<tr><td>content</td></tr>"));
|
|
|
|
el.draggable({ cancel: '' });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50, "<" + typeName + ">");
|
|
|
|
el.draggable("destroy");
|
|
|
|
el.remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("defaults", function() {
|
2008-11-12 02:52:31 +00:00
|
|
|
el = $('<div></div>').draggable();
|
|
|
|
$.each(defaults, function(key, val) {
|
|
|
|
var actual = el.data(key + ".draggable"), expected = val;
|
|
|
|
same(actual, expected, key);
|
|
|
|
});
|
|
|
|
el.remove();
|
2008-06-07 06:09:04 +00:00
|
|
|
});
|
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
test("No options, relative", function() {
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable1").draggable();
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("No options, absolute", function() {
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable2").draggable();
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-06-07 18:03:19 +00:00
|
|
|
module("draggable: Options");
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ axis: false }, default", function() {
|
|
|
|
el = $("#draggable2").draggable({ axis: false });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
2008-06-06 03:58:15 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ axis: 'x' }", function() {
|
|
|
|
el = $("#draggable2").draggable({ axis: "x" });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 0);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("{ axis: 'y' }", function() {
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable2").draggable({ axis: "y" });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(0, 50);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ axis: ? }, unexpected", function() {
|
|
|
|
var unexpected = {
|
|
|
|
"true": true,
|
|
|
|
"{}": {},
|
|
|
|
"[]": [],
|
|
|
|
"null": null,
|
|
|
|
"undefined": undefined,
|
|
|
|
"function() {}": function() {}
|
|
|
|
};
|
|
|
|
$.each(unexpected, function(key, val) {
|
|
|
|
el = $("#draggable2").draggable({ axis: val });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50, "axis: " + key);
|
|
|
|
el.draggable("destroy");
|
|
|
|
})
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("{ cancel: 'span' }", function() {
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable2").draggable();
|
|
|
|
drag("#draggable2 span", 50, 50);
|
|
|
|
moved(50, 50);
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
el.draggable("destroy");
|
|
|
|
|
|
|
|
el = $("#draggable2").draggable({ cancel: 'span' });
|
|
|
|
drag("#draggable2 span", 50, 50);
|
|
|
|
moved(0, 0);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ cancel: ? }, unexpected", function() {
|
|
|
|
var unexpected = {
|
|
|
|
"true": true,
|
|
|
|
"false": false,
|
|
|
|
"{}": {},
|
|
|
|
"[]": [],
|
|
|
|
"null": null,
|
|
|
|
"undefined": undefined,
|
|
|
|
"function() {return '';}": function() {return '';},
|
|
|
|
"function() {return true;}": function() {return true;},
|
|
|
|
"function() {return false;}": function() {return false;}
|
|
|
|
};
|
|
|
|
$.each(unexpected, function(key, val) {
|
|
|
|
el = $("#draggable2").draggable({ cancel: val });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
var expected = [50, 50];
|
|
|
|
moved(expected[0], expected[1], "cancel: " + key);
|
|
|
|
el.draggable("destroy");
|
|
|
|
})
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ containment: 'parent' }, relative", function() {
|
|
|
|
el = $("#draggable1").draggable({ containment: 'parent' });
|
|
|
|
var p = el.parent(), po = p.offset();
|
|
|
|
drag(el, -100, -100);
|
|
|
|
var expected = {
|
|
|
|
left: po.left + border(p, 'left') + margin(el, 'left'),
|
|
|
|
top: po.top + border(p, 'top') + margin(el, 'top')
|
|
|
|
}
|
2008-10-13 21:32:42 +00:00
|
|
|
same(offsetAfter, expected, 'compare offset to parent');
|
2008-06-07 06:09:04 +00:00
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ containment: 'parent' }, absolute", function() {
|
|
|
|
el = $("#draggable2").draggable({ containment: 'parent' });
|
|
|
|
var p = el.parent(), po = p.offset();
|
|
|
|
drag(el, -100, -100);
|
|
|
|
var expected = {
|
|
|
|
left: po.left + border(p, 'left') + margin(el, 'left'),
|
|
|
|
top: po.top + border(p, 'top') + margin(el, 'top')
|
|
|
|
}
|
2008-10-13 21:32:42 +00:00
|
|
|
same(offsetAfter, expected, 'compare offset to parent');
|
2008-06-07 06:09:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("{ cursor: 'move' }", function() {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
function getCursor() { return $("body").css("cursor"); }
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
expect(2);
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
var expected = "move", actual, before, after;
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable2").draggable({
|
|
|
|
cursor: expected,
|
2008-11-14 03:00:16 +00:00
|
|
|
start: function(event, ui) {
|
2008-06-07 06:09:04 +00:00
|
|
|
actual = getCursor();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
before = getCursor();
|
|
|
|
drag("#draggable2", -1, -1);
|
|
|
|
after = getCursor();
|
|
|
|
|
|
|
|
equals(actual, expected, "start callback: cursor '" + expected + "'");
|
|
|
|
equals(after, before, "after drag: cursor restored");
|
2008-06-04 02:34:33 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ cursorAt: { left: -5, top: -5 } }", function() {
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
expect(4);
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-06 06:34:09 +00:00
|
|
|
var dx = -3, dy = -3;
|
2008-06-06 03:58:15 +00:00
|
|
|
var ox = 5, oy = 5;
|
|
|
|
var cax = -5, cay = -5;
|
|
|
|
|
|
|
|
var actual = null;
|
2008-06-04 02:34:33 +00:00
|
|
|
$("#draggable2").draggable({
|
2008-06-06 03:58:15 +00:00
|
|
|
cursorAt: { left: cax, top: cay },
|
2008-11-14 03:00:16 +00:00
|
|
|
drag: function(event, ui) {
|
2008-06-06 03:58:15 +00:00
|
|
|
actual = ui.absolutePosition;
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
});
|
2008-06-06 03:58:15 +00:00
|
|
|
var el = $("#draggable2").data("draggable").element;
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-06 03:58:15 +00:00
|
|
|
var before = el.offset();
|
|
|
|
var pos = { clientX: before.left + ox, clientY: before.top + oy };
|
|
|
|
$("#draggable2").simulate("mousedown", pos);
|
2008-06-06 06:34:09 +00:00
|
|
|
pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy };
|
|
|
|
$(document).simulate("mousemove", pos);
|
|
|
|
$(document).simulate("mousemove", pos);
|
2008-06-06 03:58:15 +00:00
|
|
|
$("#draggable2").simulate("mouseup", pos);
|
2008-06-06 06:34:09 +00:00
|
|
|
var expected = {
|
|
|
|
left: before.left + ox - cax + dx,
|
|
|
|
top: before.top + oy - cay + dy
|
|
|
|
};
|
2008-06-06 03:58:15 +00:00
|
|
|
|
|
|
|
equals(actual.left, expected.left, "Absolute: -1px left");
|
|
|
|
equals(actual.top, expected.top, "Absolute: -1px top");
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-06-06 03:58:15 +00:00
|
|
|
var actual = null;
|
2008-06-04 02:34:33 +00:00
|
|
|
$("#draggable1").draggable({
|
2008-06-06 03:58:15 +00:00
|
|
|
cursorAt: { left: cax, top: cay },
|
2008-11-14 03:00:16 +00:00
|
|
|
drag: function(event, ui) {
|
2008-06-06 03:58:15 +00:00
|
|
|
actual = ui.absolutePosition;
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
});
|
2008-06-06 03:58:15 +00:00
|
|
|
var el = $("#draggable2").data("draggable").element;
|
|
|
|
|
|
|
|
var before = el.offset();
|
|
|
|
var pos = { clientX: before.left + ox, clientY: before.top + oy };
|
|
|
|
$("#draggable2").simulate("mousedown", pos);
|
2008-06-06 06:34:09 +00:00
|
|
|
pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy };
|
|
|
|
$(document).simulate("mousemove", pos);
|
|
|
|
$(document).simulate("mousemove", pos);
|
2008-06-06 03:58:15 +00:00
|
|
|
$("#draggable2").simulate("mouseup", pos);
|
2008-06-06 06:34:09 +00:00
|
|
|
var expected = {
|
|
|
|
left: before.left + ox - cax + dx,
|
|
|
|
top: before.top + oy - cay + dy
|
|
|
|
};
|
2008-06-06 03:58:15 +00:00
|
|
|
|
|
|
|
equals(actual.left, expected.left, "Relative: -1px left");
|
|
|
|
equals(actual.top, expected.top, "Relative: -1px top");
|
2008-06-04 02:34:33 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ distance: 10 }", function() {
|
|
|
|
|
|
|
|
el = $("#draggable2").draggable({ distance: 10 });
|
|
|
|
drag(el, -9, -9);
|
|
|
|
moved(0, 0, 'distance not met');
|
|
|
|
|
|
|
|
drag(el, -10, -10);
|
|
|
|
moved(-10, -10, 'distance met');
|
|
|
|
|
|
|
|
drag(el, 9, 9);
|
|
|
|
moved(0, 0, 'distance not met');
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
test("{ grid: [50, 50] }, relative", function() {
|
|
|
|
el = $("#draggable1").draggable({ grid: [50, 50] });
|
|
|
|
drag(el, 24, 24);
|
|
|
|
moved(0, 0);
|
|
|
|
drag(el, 26, 25);
|
|
|
|
moved(50, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ grid: [50, 50] }, absolute", function() {
|
|
|
|
el = $("#draggable2").draggable({ grid: [50, 50] });
|
|
|
|
drag(el, 24, 24);
|
|
|
|
moved(0, 0);
|
|
|
|
drag(el, 26, 25);
|
|
|
|
moved(50, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ handle: 'span' }", function() {
|
|
|
|
el = $("#draggable2").draggable({ handle: 'span' });
|
|
|
|
|
|
|
|
drag("#draggable2 span", 50, 50);
|
|
|
|
moved(50, 50, "drag span");
|
|
|
|
|
|
|
|
drag("#draggable2", 50, 50);
|
|
|
|
moved(0, 0, "drag element");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'clone' }, relative", function() {
|
|
|
|
el = $("#draggable1").draggable({ helper: "clone" });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(0, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'clone' }, absolute", function() {
|
|
|
|
el = $("#draggable2").draggable({ helper: "clone" });
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(0, 0);
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("{ opacity: 0.5 }", function() {
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
expect(1);
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var opacity = null;
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable2").draggable({
|
2008-06-04 02:34:33 +00:00
|
|
|
opacity: 0.5,
|
2008-11-14 03:00:16 +00:00
|
|
|
start: function(event, ui) {
|
2008-06-04 02:34:33 +00:00
|
|
|
opacity = $(this).css("opacity");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
drag("#draggable2", -1, -1);
|
2008-06-06 03:58:15 +00:00
|
|
|
|
|
|
|
equals(opacity, 0.5, "start callback: opacity is");
|
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("{ zIndex: 10 }", function() {
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
expect(1);
|
|
|
|
|
2008-06-06 03:58:15 +00:00
|
|
|
var expected = 10, actual;
|
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var zIndex = null;
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable2").draggable({
|
2008-06-06 03:58:15 +00:00
|
|
|
zIndex: expected,
|
2008-11-14 03:00:16 +00:00
|
|
|
start: function(event, ui) {
|
2008-06-06 03:58:15 +00:00
|
|
|
actual = $(this).css("zIndex");
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
drag("#draggable2", -1, -1);
|
2008-06-06 03:58:15 +00:00
|
|
|
|
|
|
|
equals(actual, expected, "start callback: zIndex is");
|
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-06-07 18:03:19 +00:00
|
|
|
module("draggable: Callbacks");
|
2008-06-07 06:09:04 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
test("callbacks occurance count", function() {
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
expect(3);
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var start = 0, stop = 0, dragc = 0;
|
2008-06-07 06:09:04 +00:00
|
|
|
el = $("#draggable2").draggable({
|
2008-06-04 02:34:33 +00:00
|
|
|
start: function() { start++; },
|
|
|
|
drag: function() { dragc++; },
|
|
|
|
stop: function() { stop++; }
|
|
|
|
});
|
|
|
|
|
2008-06-07 06:09:04 +00:00
|
|
|
drag(el, 10, 10);
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
equals(start, 1, "start callback should happen exactly once");
|
2008-06-24 13:25:15 +00:00
|
|
|
equals(dragc, 3 + 1, "drag callback should happen exactly once per mousemove + 1");
|
2008-06-04 02:34:33 +00:00
|
|
|
equals(stop, 1, "stop callback should happen exactly once");
|
2008-06-06 03:58:15 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2008-06-06 06:34:09 +00:00
|
|
|
|
2008-09-15 20:26:42 +00:00
|
|
|
module("draggable: Scroll offsets");
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, relative, with scroll offset on parent", function() {
|
|
|
|
el = $("#draggable1").draggable({ helper: "original" });
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, relative, with scroll offset on root", function() {
|
|
|
|
el = $("#draggable1").draggable({ helper: "original" });
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, relative, with scroll offset on root and parent", function() {
|
|
|
|
el = $("#draggable1").draggable({ helper: "original" });
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, absolute, with scroll offset on parent", function() {
|
|
|
|
el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, absolute, with scroll offset on root", function() {
|
|
|
|
el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, absolute, with scroll offset on root and parent", function() {
|
|
|
|
el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" });
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
//Fixed not for IE < 7
|
|
|
|
if(!($.browser.msie && $.browser.version < 7)) {
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, fixed, with scroll offset on parent", function() {
|
|
|
|
el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, fixed, with scroll offset on root", function() {
|
|
|
|
el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'original' }, fixed, with scroll offset on root and parent", function() {
|
|
|
|
el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" });
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
drag(el, 50, 50);
|
|
|
|
moved(50, 50);
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test("{ helper: 'clone' }, absolute", function() {
|
|
|
|
|
|
|
|
var helperOffset = null;
|
|
|
|
var origOffset = $("#draggable1").offset();
|
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
|
2008-09-15 20:26:42 +00:00
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
} });
|
|
|
|
|
|
|
|
drag(el, 1, 1);
|
|
|
|
|
2008-10-13 21:32:42 +00:00
|
|
|
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
|
2008-09-15 20:26:42 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
|
|
|
|
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
var helperOffset = null;
|
|
|
|
var origOffset = $("#draggable1").offset();
|
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
|
2008-09-15 20:26:42 +00:00
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
} });
|
|
|
|
|
|
|
|
drag(el, 1, 1);
|
|
|
|
|
2008-10-13 21:32:42 +00:00
|
|
|
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
|
2008-09-15 20:26:42 +00:00
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'clone' }, absolute with scroll offset on root", function() {
|
|
|
|
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
var helperOffset = null;
|
|
|
|
var origOffset = $("#draggable1").offset();
|
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
|
2008-09-15 20:26:42 +00:00
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
} });
|
|
|
|
|
|
|
|
drag(el, 1, 1);
|
|
|
|
|
2008-10-13 21:32:42 +00:00
|
|
|
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
|
2008-09-15 20:26:42 +00:00
|
|
|
$(document).scrollTop(0);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test("{ helper: 'clone' }, absolute with scroll offset on root and parent", function() {
|
|
|
|
|
|
|
|
$(document).scrollTop(100);
|
|
|
|
$("#main")[0].scrollTop = 100;
|
|
|
|
var helperOffset = null;
|
|
|
|
var origOffset = $("#draggable1").offset();
|
|
|
|
|
2008-11-14 03:00:16 +00:00
|
|
|
el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
|
2008-09-15 20:26:42 +00:00
|
|
|
helperOffset = ui.helper.offset();
|
|
|
|
} });
|
|
|
|
|
|
|
|
drag(el, 1, 1);
|
|
|
|
|
2008-10-13 21:32:42 +00:00
|
|
|
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
|
2008-09-15 20:26:42 +00:00
|
|
|
$(document).scrollTop(0);
|
|
|
|
$("#main")[0].scrollTop = 0;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2008-11-03 12:44:50 +00:00
|
|
|
module("draggable: behaviour");
|
|
|
|
|
|
|
|
test("Events should not be executed on the element if drag is initiated", function() {
|
|
|
|
//TODO: Implement missing test
|
|
|
|
});
|
|
|
|
|
2008-09-15 20:26:42 +00:00
|
|
|
|
2008-06-07 18:03:19 +00:00
|
|
|
module("draggable: Tickets");
|
2008-06-06 06:34:09 +00:00
|
|
|
|
2008-09-15 20:26:42 +00:00
|
|
|
/* This needs to be rewritten
|
|
|
|
|
2008-06-06 06:34:09 +00:00
|
|
|
test("#2965 cursorAt with margin", function() {
|
|
|
|
|
|
|
|
expect(2);
|
|
|
|
|
|
|
|
var ox = 0, oy = 0;
|
|
|
|
|
|
|
|
var actual, expected;
|
|
|
|
$("#draggable2").draggable({
|
|
|
|
cursorAt: { left: ox, top: oy },
|
2008-11-14 03:00:16 +00:00
|
|
|
drag: function(event, ui) {
|
2008-06-06 06:34:09 +00:00
|
|
|
actual = ui.absolutePosition;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var el = $("#draggable2").data("draggable").element;
|
|
|
|
|
|
|
|
$("#draggable2").css('margin', '0px !important');
|
|
|
|
|
|
|
|
var before = el.offset();
|
|
|
|
var pos = { clientX: before.left + ox, clientY: before.top + oy };
|
|
|
|
$("#draggable2").simulate("mousedown", pos);
|
2008-06-26 10:20:48 +00:00
|
|
|
$(document).simulate("mousemove", { clientX: pos.clientX + 1, clientY: pos.clientY + 1});
|
2008-06-06 06:34:09 +00:00
|
|
|
$(document).simulate("mousemove", pos);
|
|
|
|
$("#draggable2").simulate("mouseup", pos);
|
|
|
|
var expected = actual;
|
|
|
|
actual = undefined;
|
|
|
|
|
|
|
|
var marg = 13;
|
|
|
|
|
|
|
|
$("#draggable2").css('margin', marg + 'px !important');
|
|
|
|
var before = el.offset();
|
|
|
|
var pos = { clientX: before.left + ox - marg, clientY: before.top + oy - marg };
|
|
|
|
$("#draggable2").simulate("mousedown", pos);
|
2008-06-26 10:20:48 +00:00
|
|
|
$(document).simulate("mousemove", { clientX: pos.clientX + 1, clientY: pos.clientY + 1});
|
2008-06-06 06:34:09 +00:00
|
|
|
$(document).simulate("mousemove", pos);
|
|
|
|
$("#draggable2").simulate("mouseup", pos);
|
|
|
|
|
|
|
|
equals(actual.left, expected.left, "10px margin. left");
|
|
|
|
equals(actual.top, expected.top, "10px margin. top");
|
|
|
|
|
|
|
|
});
|
2008-09-15 20:26:42 +00:00
|
|
|
*/
|
2008-06-09 05:59:18 +00:00
|
|
|
|
|
|
|
})(jQuery);
|