Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added position offset to dragged item, if within a fixed or absolutel… #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/angular-sortable-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
var targetLeft = coords.x;
var targetTop = coords.y;
var helperRect = clone[0].getBoundingClientRect();
var myParent = getParentPositioned($element[0]);

var body = document.body;

Expand All @@ -445,6 +446,13 @@
if(targetLeft + helperRect.width > containmentRect.left + body.scrollLeft + containmentRect.width) // right boundary
targetLeft = containmentRect.left + body.scrollLeft + containmentRect.width - helperRect.width;
}

//add parent position offset, if element is within a positioned element
if(myParent){
targetTop = targetTop - myParent.top;
targetLeft = targetLeft - myParent.left;
}

this.style.left = targetLeft - body.scrollLeft + 'px';
this.style.top = targetTop - body.scrollTop + 'px';
};
Expand Down Expand Up @@ -594,6 +602,24 @@
return element[matchingFunction](selector);
}

//get closest parent node that is positioned
function getParentPositioned(el){
el = el.parentNode;

while(el !== document.documentElement){
var pos = angular.element(el).css("position");
if(pos != 'static' && pos != ''){
console.log(el);
console.log(el.getBoundingClientRect());
return el.getBoundingClientRect();
} else{
el = el.parentNode;
}
}
return null;
}


var closestElement = angular.element.prototype.closest || function (selector){
var el = this[0].parentNode;
while(el !== document.documentElement && !el[matchingFunction](selector))
Expand Down
2 changes: 1 addition & 1 deletion src/angular-sortable-view.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.