Skip to content
Permalink
Browse files

draggable: second partial fix for remaining scroll issues (for the sp…

…ecial case, subtract scrollLeft/scrollTop already in getParentOffset, so calculations become easier in _generatePosition)
  • Loading branch information...
Paul Bakaus
Paul Bakaus committed Jan 8, 2009
1 parent 1c647d9 commit 122786c4b2216321f53d10ab094f96f9d1ecec11
Showing with 13 additions and 10 deletions.
  1. +13 −10 ui/ui.draggable.js
@@ -196,7 +196,18 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {

_getParentOffset: function() {

this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); //Get the offsetParent and cache its position
//Get the offsetParent and cache its position
this.offsetParent = this.helper.offsetParent();
var po = this.offsetParent.offset();

// This is a special case where we need to modify a offset calculated on start, since the following happened:
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) {
po.left += this.scrollParent.scrollLeft();
po.top += this.scrollParent.scrollTop();
}

if((this.offsetParent[0] == document.body && $.browser.mozilla) //Ugly FF3 fix
|| (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
@@ -289,15 +300,7 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {

_generatePosition: function(event) {

var o = this.options, scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);

// This is a special case where we need to modify a offset calculated on start, since the following happened:
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) {
this.offset.parent = this._getParentOffset();
}
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);

// This is another very weird special case that only happens for relative elements:
// 1. If the css position is relative

0 comments on commit 122786c

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