Bug fix: getElementPosition() didn't work with Coordinates objects where either x or y were 0 #10

Merged
merged 3 commits into from May 16, 2011

Projects

None yet

2 participants

@wieslander
Contributor

Passing a Coordinates object to getElementPosition() where either x or y is zero causes caused both x and yin the return value to be zero, like this:

var pos = getElementPosition({x: 0, y: 100}):
// pos is now {x: 0, y: 0}, should be {x: 0, y: 100}

This also has the side effect that passing such a Coordinates object as the relativeTo parameter does not work:

var otherPos = new Coordinates(0, 50);
var relative = getElementPosition({x: 100, y: 100}, otherPos);
// relative is now {x: 100, y: 100}, should be {x: 100, y: 50}

The underlying problem is the following check in Style.js, which obviously fails if either x or y is zero:

if (!elem.parentNode && elem.x && elem.y) {
    /* it's just a MochiKit.Style.Coordinates object */

This patch adds unit tests to expose these issues and adjusts the check above to fix the problem.

@cederberg cederberg merged commit 181677b into mochi:master May 16, 2011
@cederberg
Member

Thanks! Great to see proper tests to accompany the code fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment