Skip to content

Instantly share code, notes, and snippets.

@kwhitaker
Created April 22, 2013 21:21
Show Gist options
  • Save kwhitaker/5438658 to your computer and use it in GitHub Desktop.
Save kwhitaker/5438658 to your computer and use it in GitHub Desktop.
jsPlumb function that I'm having issues with
var adjustForParentOffsetAndScroll = function(xy, el) {
var offsetParent = null, result = xy;
if (el.tagName.toLowerCase() === "svg" && el.parentNode) {
offsetParent = el.parentNode;
}
else if (el.offsetParent) {
offsetParent = el.offsetParent;
}
if (offsetParent != null) {
var po = offsetParent.tagName.toLowerCase() === "body" ? {left:0,top:0} : _getOffset(offsetParent, _currentInstance),
so = offsetParent.tagName.toLowerCase() === "body" ? {left:0,top:0} : {left:offsetParent.scrollLeft, top:offsetParent.scrollTop};
// i thought it might be cool to do this:
// lastReturnValue[0] = lastReturnValue[0] - offsetParent.offsetLeft + offsetParent.scrollLeft;
// lastReturnValue[1] = lastReturnValue[1] - offsetParent.offsetTop + offsetParent.scrollTop;
// but i think it ignores margins. my reasoning was that it's quicker to not hand off to some underlying
// library.
//FIXME - this line *seems* to fix the issue of this thing going bonkers with the end point creation,
// but I can't be sure that it will work, since I haven't tracked down what the actual problem is.
//result[0] = xy[0] - 60;
result[0] = xy[0] - po.left + so.top;
result[1] = xy[1] - po.top + so.top;
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment