boolean c = false;
String p1 = p.substring(0, p.indexOf("-"));
String p2 = p.substring(p.indexOf("-") + 1, ((c = p.contains("?")) ? p.indexOf("?") : p.length()));
// Subtract the aligned el's internal xy from the target's offset xy
// plus custom offset to get the aligned el's new offset xy
Point a1 = getAnchorXY(p1, true);
Point a2 = el.getAnchorXY(p2, false);
int x = a2.x - a1.x + ox;
int y = a2.y - a1.y + oy;
if (c) {
// constrain the aligned el to viewport if necessary
int w = getWidth();
int h = getHeight();
Region r = el.getRegion();
// 5px of margin for ie
int dw = XDOM.getViewWidth(false) - 10;
int dh = XDOM.getViewHeight(false) - 10;
// If we are at a viewport boundary and the aligned el is anchored on a
// target border that is
// perpendicular to the vp border, allow the aligned el to slide on that
// border,
// otherwise swap the aligned el to the opposite border of the target.
char p1y = p1.charAt(0), p1x = p1.charAt(p1.length() - 1);
char p2y = p2.charAt(0), p2x = p2.charAt(p2.length() - 1);
boolean swapY = ((p1y == 't' && p2y == 'b') || (p1y == 'b' && p2y == 't'));
boolean swapX = ((p1x == 'r' && p2x == 'l') || (p1x == 'l' && p2x == 'r'));
int scrollX = XDOM.getBodyScrollLeft() + 5;
int scrollY = XDOM.getBodyScrollTop() + 5;
if ((x + w) > dw + scrollX) {
x = swapX ? r.left - w : dw + scrollX - w;
}
if (x < scrollX) {
x = swapX ? r.right : scrollX;
}
if ((y + h) > (dh + scrollY)) {
y = swapY ? r.top - h : dh + scrollY - h;
}
if (y < scrollY) {
y = swapY ? r.bottom : scrollY;
}
}
return new Point(x, y);
}