diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2013-08-12 19:31:39 -0400 |
---|---|---|
committer | Mike Sherov <mike.sherov@gmail.com> | 2013-08-12 19:32:01 -0400 |
commit | 263d07894493aafcdc6a565f9f9c079b4b8f5d80 (patch) | |
tree | c2744e443c69c869081f29213d6579cdc7fbccd4 /ui | |
parent | 1c58573a95778010c247605ebb1915d8e8739423 (diff) | |
download | jquery-ui-263d07894493aafcdc6a565f9f9c079b4b8f5d80.tar.gz jquery-ui-263d07894493aafcdc6a565f9f9c079b4b8f5d80.zip |
Draggable: Ignore scroll offsets for abspos draggables. Fixes #9315 - Draggable: jumps down with offset of scrollbar
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.draggable.js | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js index ab1e800cd..2bdc20255 100644 --- a/ui/jquery.ui.draggable.js +++ b/ui/jquery.ui.draggable.js @@ -452,7 +452,12 @@ $.widget("ui.draggable", $.ui.mouse, { var mod = d === "absolute" ? 1 : -1, document = this.document[ 0 ], - scroll = this.cssPosition === "absolute" && !( this.scrollParent[ 0 ] !== document && $.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ? this.offsetParent : this.scrollParent; + useOffsetParent = this.cssPosition === "absolute" && ( this.scrollParent[ 0 ] === document || !$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ), + scroll = useOffsetParent ? this.offsetParent : this.scrollParent, + // we need to test if offsetParent was used here because Blink incorrectly reports a 0 scrollTop + // on document.documentElement when the page is scrolled. Checking for offsetParent normalizes + // this across browsers. Blink bug: https://code.google.com/p/chromium/issues/detail?id=157855 + scrollIsRootNode = useOffsetParent && ( /(html|body)/i ).test( scroll[ 0 ].nodeName ); //Cache the scroll if (!this.offset.scroll) { @@ -464,13 +469,13 @@ $.widget("ui.draggable", $.ui.mouse, { pos.top + // The absolute mouse position this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border) - ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : this.offset.scroll.top ) * mod ) + ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : this.offset.scroll.top ) ) * mod) ), left: ( pos.left + // The absolute mouse position this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border) - ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : this.offset.scroll.left ) * mod ) + ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : this.offset.scroll.left ) * mod) ) }; @@ -481,7 +486,12 @@ $.widget("ui.draggable", $.ui.mouse, { var containment, co, top, left, o = this.options, document = this.document[ 0 ], - scroll = this.cssPosition === "absolute" && !( this.scrollParent[ 0 ] !== document && $.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ? this.offsetParent : this.scrollParent, + useOffsetParent = this.cssPosition === "absolute" && ( this.scrollParent[ 0 ] === document || !$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ), + scroll = useOffsetParent ? this.offsetParent : this.scrollParent, + // we need to test if offsetParent was used here because Blink incorrectly reports a 0 scrollTop + // on document.documentElement when the page is scrolled. Checking for offsetParent normalizes + // this across browsers. Blink bug: https://code.google.com/p/chromium/issues/detail?id=157855 + scrollIsRootNode = useOffsetParent && ( /(html|body)/i ).test( scroll[ 0 ].nodeName ), pageX = event.pageX, pageY = event.pageY; @@ -542,14 +552,14 @@ $.widget("ui.draggable", $.ui.mouse, { this.offset.click.top - // Click offset (relative to the element) this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent this.offset.parent.top + // The offsetParent's offset without borders (offset + border) - ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : this.offset.scroll.top ) + ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : this.offset.scroll.top ) ) ), left: ( pageX - // The absolute mouse position this.offset.click.left - // Click offset (relative to the element) this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent this.offset.parent.left + // The offsetParent's offset without borders (offset + border) - ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : this.offset.scroll.left ) + ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : ( scrollIsRootNode ? 0 : this.offset.scroll.left ) ) ) }; |