Skip to content

Commit

Permalink
Handle positioning correctly when inside a positioned parent
Browse files Browse the repository at this point in the history
and that parent may not be the containment element
  • Loading branch information
mnzaki committed May 2, 2017
1 parent f09c970 commit d1d1c64
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/angular-sortable-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@

var target = $element;
var clientRect = $element[0].getBoundingClientRect();
var parentRect = getPositionedParentRect($element[0]);
var clone;

if(!helper) helper = $controllers[0].helper;
Expand Down Expand Up @@ -459,8 +460,10 @@
if(targetLeft + helperRect.width > containmentRect.left + body.scrollLeft + containmentRect.width) // right boundary
targetLeft = containmentRect.left + body.scrollLeft + containmentRect.width - helperRect.width;

targetLeft -= containmentRect.left;
targetTop -= containmentRect.top;
if (parentRect) {
targetLeft -= parentRect.left;
targetTop -= parentRect.top;
}
}
this.style.left = targetLeft - body.scrollLeft + 'px';
this.style.top = targetTop - body.scrollTop + 'px';
Expand Down Expand Up @@ -499,6 +502,16 @@
}, clone, $element, placeholder, $controllers[0].getPart(), $scope.$index);
}
}

function getPositionedParentRect(el) {
while (el !== document.documentElement) {
el = el.parentNode;
var cssPos = el.style.position;
if (cssPos != '' && cssPos != 'static') {
return el.getBoundingClientRect();
}
}
}
}
};
}]);
Expand Down

0 comments on commit d1d1c64

Please sign in to comment.