aboutsummaryrefslogtreecommitdiffstats
path: root/tests/draggable.js
diff options
context:
space:
mode:
authorPaul Bakaus <paul.bakaus@googlemail.com>2008-09-15 20:26:42 +0000
committerPaul Bakaus <paul.bakaus@googlemail.com>2008-09-15 20:26:42 +0000
commit7ba2beb903276f43e1ac322abd6e1fcc522e3b9e (patch)
tree9f5e3f48650f28a488f14ddfe8b84a99d9c8a5cf /tests/draggable.js
parentee30dbbd216065aeee60cddf3ab04e9fa3eee564 (diff)
downloadjquery-ui-7ba2beb903276f43e1ac322abd6e1fcc522e3b9e.tar.gz
jquery-ui-7ba2beb903276f43e1ac322abd6e1fcc522e3b9e.zip
- kickass draggable refactoring - fixes many bugs, many edge case issues
- added many new tests to draggable, especially related to scrolling and helper clone
Diffstat (limited to 'tests/draggable.js')
-rw-r--r--tests/draggable.js159
1 files changed, 159 insertions, 0 deletions
diff --git a/tests/draggable.js b/tests/draggable.js
index 9234b3567..6045d00f2 100644
--- a/tests/draggable.js
+++ b/tests/draggable.js
@@ -445,8 +445,166 @@ test("callbacks occurance count", function() {
});
+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();
+
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(e, ui) {
+ helperOffset = ui.helper.offset();
+ } });
+
+ drag(el, 1, 1);
+
+ compare2({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+
+});
+
+test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {
+
+ $("#main")[0].scrollTop = 100;
+ var helperOffset = null;
+ var origOffset = $("#draggable1").offset();
+
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(e, ui) {
+ helperOffset = ui.helper.offset();
+ } });
+
+ drag(el, 1, 1);
+
+ compare2({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+ $("#main")[0].scrollTop = 0;
+
+});
+
+test("{ helper: 'clone' }, absolute with scroll offset on root", function() {
+
+ $(document).scrollTop(100);
+ var helperOffset = null;
+ var origOffset = $("#draggable1").offset();
+
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(e, ui) {
+ helperOffset = ui.helper.offset();
+ } });
+
+ drag(el, 1, 1);
+
+ compare2({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+ $(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();
+
+ el = $("#draggable1").draggable({ helper: "clone", drag: function(e, ui) {
+ helperOffset = ui.helper.offset();
+ } });
+
+ drag(el, 1, 1);
+
+ compare2({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
+ $(document).scrollTop(0);
+ $("#main")[0].scrollTop = 0;
+
+});
+
+
module("draggable: Tickets");
+/* This needs to be rewritten
+
test("#2965 cursorAt with margin", function() {
expect(2);
@@ -487,5 +645,6 @@ test("#2965 cursorAt with margin", function() {
equals(actual.top, expected.top, "10px margin. top");
});
+*/
})(jQuery);