]> source.dussan.org Git - jquery-ui.git/commitdiff
Draggable: Check all parents for fixed positioning when scrolling
authorMike Sherov <mike.sherov@gmail.com>
Sat, 23 Aug 2014 19:34:04 +0000 (15:34 -0400)
committerMike Sherov <mike.sherov@gmail.com>
Sat, 23 Aug 2014 19:34:04 +0000 (15:34 -0400)
Fixes #9612

tests/unit/draggable/draggable_core.js
ui/draggable.js

index de88b1947419338f4d9f9b615c6fd4d86ca25912..81c31e22f1de76c1c852f19ebb0f858255fbe25e 100644 (file)
@@ -182,25 +182,33 @@ test( "#9315: jumps down with offset of scrollbar", function() {
                });
 });
 
-test( "#5009: scroll not working with parent's position fixed", function() {
+test( "scroll offset with fixed ancestors", 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 when parent position is fixed" );
-                               equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
-                               $( document ).scrollTop( 0 ).scrollLeft( 0 );
-                       }
-               });
+               element = $( "#draggable1" )
+                       // http://bugs.jqueryui.com/ticket/5009
+                       // scroll not working with parent's position fixed
+                       .wrap( "<div id='wrapper' />" )
+                       // http://bugs.jqueryui.com/ticket/9612
+                       // abspos elements inside of fixed elements moving away from the mouse when scrolling
+                       .wrap( "<div id='wrapper2' />" )
+                       .draggable({
+                               drag: function() {
+                                       startValue += 100;
+                                       $( document ).scrollTop( startValue ).scrollLeft( startValue );
+                               },
+                               stop: function( event, ui ) {
+                                       equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
+                                       equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
+                                       $( document ).scrollTop( 0 ).scrollLeft( 0 );
+                               }
+                       });
 
        TestHelpers.forceScrollableWindow();
 
        $( "#wrapper" ).css( "position", "fixed" );
+       $( "#wrapper2" ).css( "position", "absolute" );
 
        element.simulate( "drag", {
                dx: 10,
index 8cbcfe1ab59fa195d9a0f9868619fa7e84d8c1eb..ebafaeb83347ddcb63c9ed6e2d233071eba241e7 100644 (file)
@@ -174,7 +174,9 @@ $.widget("ui.draggable", $.ui.mouse, {
                this.cssPosition = this.helper.css( "position" );
                this.scrollParent = this.helper.scrollParent( true );
                this.offsetParent = this.helper.offsetParent();
-               this.offsetParentCssPosition = this.offsetParent.css( "position" );
+               this.hasFixedAncestor = this.helper.parents().filter(function() {
+                               return $( this ).css( "position" ) === "fixed";
+                       }).length > 0;
 
                //The element's absolute position on the page minus margins
                this.positionAbs = this.element.offset();
@@ -236,7 +238,7 @@ $.widget("ui.draggable", $.ui.mouse, {
 
        _mouseDrag: function(event, noPropagation) {
                // reset any necessary cached properties (see #5009)
-               if ( this.offsetParentCssPosition === "fixed" ) {
+               if ( this.hasFixedAncestor ) {
                        this.offset.parent = this._getParentOffset();
                }