Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Use bounding box for unknown SVG elements. Fixes #547
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Jul 7, 2013
1 parent e688326 commit 09b5810
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/position/svg.js
Expand Up @@ -2,7 +2,7 @@ PLUGINS.svg = function(api, svg, corner, adjustMethod)
{
var doc = $(document),
elem = svg[0],
result = FALSE,
result = {},
name, box, position, dimensions;

// Ascend the parentNode chain until we find an element with getBBox()
Expand Down Expand Up @@ -56,8 +56,33 @@ PLUGINS.svg = function(api, svg, corner, adjustMethod)
result = PLUGINS.polys.polygon(result, corner);
break;

// Invalid shape
default: return FALSE;
// Unknown shape... use bounding box as fallback
default:
box = elem.getBBox();
mtx = elem.getScreenCTM();
root = elem.farthestViewportElement || elem;

// Return if no createSVGPoint method is found
if(!root.createSVGPoint) { return FALSE; }

// Create our point var
point = root.createSVGPoint();

// Adjust top and left
point.x = box.x;
point.y = box.y;
tPoint = point.matrixTransform(mtx);
result.position = {
left: tPoint.x, top: tPoint.y
};

// Adjust width and height
point.x += box.width;
point.y += box.height;
tPoint = point.matrixTransform(mtx);
result.width = tPoint.x - result.position.left;
result.height = tPoint.y - result.position.top;
break;
}

// Adjust by scroll offset
Expand Down

0 comments on commit 09b5810

Please sign in to comment.