Skip to content
Permalink
Browse files

draggable: added missing default for zIndex and cursorAt, added missi…

…ng scroll tests (unfortunately showing big regressions that need to be fixed prior to 1.6)
  • Loading branch information
Paul Bakaus
Paul Bakaus committed Nov 21, 2008
1 parent 6528946 commit 0036aaf4b67d55e621ac2e4553a98dc80d2ca727
Showing with 196 additions and 57 deletions.
  1. +189 −52 tests/draggable.js
  2. +4 −4 tests/droppable.html
  3. +3 −1 ui/ui.draggable.js
@@ -476,85 +476,196 @@ test("callbacks occurance count", function() {

module("draggable: Scroll offsets");


function testScroll(position) {
$("#main").css('position', position);
drag(el, 50, 50);
moved(50, 50, position+' parent');

}

function setScroll(what) {
if(what) {
$(document).scrollTop(100); $(document).scrollLeft(100);
} else {
$("#main")[0].scrollTop = 100; $("#main")[0].scrollLeft = 100;
}
}

function restoreScroll(what) {
if(what) {
$(document).scrollTop(0); $(document).scrollLeft(0);
} else {
$("#main")[0].scrollTop = 0; $("#main")[0].scrollLeft = 0;
}
}

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;

setScroll();
testScroll('relative');

setScroll();
testScroll('static');

setScroll();
testScroll('absolute');

restoreScroll();

});

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);

setScroll('root');
testScroll('relative');

setScroll('root');
testScroll('static');

setScroll('root');
testScroll('absolute');

restoreScroll('root');

});

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;

setScroll();
setScroll('root');
testScroll('relative');

setScroll();
setScroll('root');
testScroll('static');

setScroll();
setScroll('root');
testScroll('absolute');

restoreScroll();
restoreScroll('root');

});

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;

setScroll();
testScroll('relative');

setScroll();
testScroll('static');

setScroll();
testScroll('absolute');

restoreScroll();

});

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);

setScroll('root');
testScroll('relative');

setScroll('root');
testScroll('static');

setScroll('root');
testScroll('absolute');

restoreScroll('root');

});

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;

setScroll();
setScroll('root');
testScroll('relative');

setScroll();
setScroll('root');
testScroll('static');

setScroll();
setScroll('root');
testScroll('absolute');

restoreScroll();
restoreScroll('root');

});

//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;

setScroll();
testScroll('relative');

setScroll();
testScroll('static');

setScroll();
testScroll('absolute');

restoreScroll();

});

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);

setScroll('root');
testScroll('relative');

setScroll('root');
testScroll('static');

setScroll('root');
testScroll('absolute');

restoreScroll('root');

});

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;

setScroll();
setScroll('root');
testScroll('relative');

setScroll();
setScroll('root');
testScroll('static');

setScroll();
setScroll('root');
testScroll('absolute');

restoreScroll();
restoreScroll('root');

});

}
@@ -571,61 +682,87 @@ test("{ helper: 'clone' }, absolute", function() {
} });

drag(el, 1, 1);

same({ 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;
setScroll();
var helperOffset = null;
var origOffset = $("#draggable1").offset();

el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
helperOffset = ui.helper.offset();
} });

$("#main").css('position', 'relative');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');

$("#main").css('position', 'static');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
$("#main")[0].scrollTop = 0;

$("#main").css('position', 'absolute');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');

restoreScroll();

});

test("{ helper: 'clone' }, absolute with scroll offset on root", function() {

$(document).scrollTop(100);
setScroll('root');
var helperOffset = null;
var origOffset = $("#draggable1").offset();

el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
helperOffset = ui.helper.offset();
} });


$("#main").css('position', 'relative');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');

$("#main").css('position', 'static');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
$(document).scrollTop(0);

$("#main").css('position', 'absolute');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');

restoreScroll('root');

});

test("{ helper: 'clone' }, absolute with scroll offset on root and parent", function() {

$(document).scrollTop(100);
$("#main")[0].scrollTop = 100;
setScroll('root');
setScroll();
var helperOffset = null;
var origOffset = $("#draggable1").offset();

el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) {
helperOffset = ui.helper.offset();
} });

$("#main").css('position', 'relative');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');

$("#main").css('position', 'static');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');

$("#main").css('position', 'absolute');
drag(el, 1, 1);
same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ');
$(document).scrollTop(0);
$("#main")[0].scrollTop = 0;

restoreScroll('root');
restoreScroll();

});

@@ -18,9 +18,8 @@
<style type="text/css">
html { border: 0; }
#main {
position:absolute !important;
top: -1000px !important;
left: -1000px !important;
top: -1000px;
left: -1000px;
}
</style>
</head>
@@ -32,9 +31,10 @@ <h2 id="userAgent"></h2>

<ol id="tests"></ol>

<div id="main">
<div id="main" style='position: absolute; width: 300px; height: 300px; overflow: auto;'>
<div id="draggable1" style="width: 25px; height: 25px;">Draggable</div>
<div id="droppable1" style="width: 100px; height: 100px;">Droppable</div>
<div style='width:1000px;height:1000px;'>&nbsp;</div>
</div>

</body>
@@ -369,6 +369,7 @@ $.extend($.ui.draggable, {
containment: false,
cssNamespace: "ui",
cursor: "default",
cursorAt: null,
delay: 0,
distance: 1,
grid: false,
@@ -386,7 +387,8 @@ $.extend($.ui.draggable, {
snap: false,
snapMode: "both",
snapTolerance: 20,
stack: false
stack: false,
zIndex: null
}
});

0 comments on commit 0036aaf

Please sign in to comment.
You can’t perform that action at this time.