]> source.dussan.org Git - jquery-ui.git/commitdiff
Draggable: Don't cache parent offset if the parent position is fixed. Fixes #5009...
authorMike Sherov <mike.sherov@gmail.com>
Wed, 3 Apr 2013 16:26:39 +0000 (12:26 -0400)
committerMike Sherov <mike.sherov@gmail.com>
Wed, 3 Apr 2013 16:26:39 +0000 (12:26 -0400)
tests/unit/draggable/draggable_core.js
ui/jquery.ui.draggable.js

index 0d693e4ffbcdfc4b8aee0fd7ac2cf5aa49fba0a1..9ef18c4b27883a22ebf583a3adf86b0ac0ae96e8 100644 (file)
@@ -129,4 +129,34 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
                });
 });
 
+test( "#5009: scroll not working with parent's position fixed", function() {
+       expect( 2 );
+
+       var startValue = 300,
+               element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
+                       drag: function() {
+                               startValue += 100;
+                               $( document ).scrollTop( startValue ).scrollLeft( startValue );
+                       },
+                       stop: function( event, ui ) {
+                               equal( ui.position.left, 10, "left position is correct despite overflow on HTML" );
+                               equal( ui.position.top, 10, "top position is correct despite overflow on HTML" );
+                               $( document ).scrollTop( 0 ).scrollLeft( 0 );
+                       }
+               }),
+               contentToForceScroll = $( "<div>" ).css({
+                       height: "20000px",
+                       width: "20000px"
+               });
+
+       $( "#qunit-fixture" ).append( contentToForceScroll );
+       $( "#wrapper" ).css( "position", "fixed" );
+
+       element.simulate( "drag", {
+               dx: 10,
+               dy: 10,
+               moves: 3
+       });
+});
+
 })( jQuery );
index 4814cb85117653a3a3d0ed4775690c86f27b9f7e..64cf339e09b67a1e68d20723d435d2504aed3f2a 100644 (file)
@@ -125,8 +125,10 @@ $.widget("ui.draggable", $.ui.mouse, {
                this._cacheMargins();
 
                //Store the helper's css position
-               this.cssPosition = this.helper.css("position");
+               this.cssPosition = this.helper.css( "position" );
                this.scrollParent = this.helper.scrollParent();
+               this.offsetParent = this.helper.offsetParent();
+               this.offsetParentCssPosition = this.offsetParent.css( "position" );
 
                //The element's absolute position on the page minus margins
                this.offset = this.positionAbs = this.element.offset();
@@ -184,6 +186,10 @@ $.widget("ui.draggable", $.ui.mouse, {
        },
 
        _mouseDrag: function(event, noPropagation) {
+               // reset any necessary cached properties (see #5009)
+               if ( this.offsetParentCssPosition === "fixed" ) {
+                       this.offset.parent = this._getParentOffset();
+               }
 
                //Compute the helpers position
                this.position = this._generatePosition(event);
@@ -320,7 +326,6 @@ $.widget("ui.draggable", $.ui.mouse, {
        _getParentOffset: function() {
 
                //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: