Skip to content
Permalink
Browse files

core: improved logic of $.fn.scrollParent, taking positioning in account

draggable: fixed and updated tests, rewrote positioning core, now passes the test suite completely in FF, IE6, IE7
  • Loading branch information...
Paul Bakaus
Paul Bakaus committed Nov 23, 2008
1 parent 0472ff1 commit a42894b1d7a248d274ff309bf8b4b3bd45a7d4a8
Showing with 142 additions and 167 deletions.
  1. +13 −48 tests/draggable.js
  2. +15 −3 ui/ui.core.js
  3. +114 −116 ui/ui.draggable.js
@@ -469,7 +469,7 @@ test("callbacks occurance count", function() {
drag(el, 10, 10);

equals(start, 1, "start callback should happen exactly once");
equals(dragc, 3 + 1, "drag callback should happen exactly once per mousemove + 1");
equals(dragc, 3, "drag callback should happen exactly once per mousemove");
equals(stop, 1, "stop callback should happen exactly once");

});
@@ -690,21 +690,24 @@ test("{ helper: 'clone' }, absolute with scroll offset on parent", function() {

setScroll();
var helperOffset = null;
var origOffset = $("#draggable1").offset();
var origOffset = null;

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

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

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

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

@@ -716,21 +719,24 @@ test("{ helper: 'clone' }, absolute with scroll offset on root", function() {

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

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

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

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

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

@@ -743,21 +749,24 @@ test("{ helper: 'clone' }, absolute with scroll offset on root and parent", func
setScroll('root');
setScroll();
var helperOffset = null;
var origOffset = $("#draggable1").offset();
var origOffset = null;

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

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

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

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

@@ -775,48 +784,4 @@ test("Events should not be executed on the element if drag is initiated", functi

module("draggable: Tickets");

/* This needs to be rewritten
test("#2965 cursorAt with margin", function() {
expect(2);
var ox = 0, oy = 0;
var actual, expected;
$("#draggable2").draggable({
cursorAt: { left: ox, top: oy },
drag: function(event, ui) {
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);
$(document).simulate("mousemove", { clientX: pos.clientX + 1, clientY: pos.clientY + 1});
$(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);
$(document).simulate("mousemove", { clientX: pos.clientX + 1, clientY: pos.clientY + 1});
$(document).simulate("mousemove", pos);
$("#draggable2").simulate("mouseup", pos);
equals(actual.left, expected.left, "10px margin. left");
equals(actual.top, expected.top, "10px margin. top");
});
*/

})(jQuery);
@@ -187,9 +187,21 @@ $.fn.extend({
},

scrollParent: function() {
return $(this).parents().filter(function() {
return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
}).eq(0);

var scrollParent;
if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
scrollParent = this.parents().filter(function() {
return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
}).eq(0);
} else {
scrollParent = this.parents().filter(function() {
return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
}).eq(0);
}

return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;


}

});

0 comments on commit a42894b

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