diff options
author | wout <wout@impinc.co.uk> | 2013-04-22 09:57:25 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-04-22 09:57:25 +0100 |
commit | 11ded2fe8fabf4392633fcdb3713a49e084746a1 (patch) | |
tree | 16c325b6261d8159bade92faf6b763acbccad148 /src/rbox.js | |
parent | a736acc12e4ca1a71b9f563f7ed361e2a3540469 (diff) | |
download | svg.js-11ded2fe8fabf4392633fcdb3713a49e084746a1.tar.gz svg.js-11ded2fe8fabf4392633fcdb3713a49e084746a1.zip |
Added the rbox() method, bumped to v0.140.15
Diffstat (limited to 'src/rbox.js')
-rw-r--r-- | src/rbox.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/rbox.js b/src/rbox.js new file mode 100644 index 0000000..02405b0 --- /dev/null +++ b/src/rbox.js @@ -0,0 +1,43 @@ +// Get the rectangular box of a given element +SVG.RBox = function(element) { + var box, zoom + , e = element.doc().parent + , zoom = element.doc().viewbox().zoom + + /* actual, native bounding box */ + box = element.node.getBoundingClientRect() + + /* get screen offset */ + this.x = box.left + this.y = box.top + + /* subtract parent offset */ + this.x -= e.offsetLeft + this.y -= e.offsetTop + + while (e = e.offsetParent) { + this.x -= e.offsetLeft + this.y -= e.offsetTop + } + + /* calculate cumulative zoom from svg documents */ + e = element + while (e = e.parent) { + if (e.type == 'svg' && e.viewbox) { + zoom *= e.viewbox().zoom + this.x -= e.x() || 0 + this.y -= e.y() || 0 + } + } + + /* recalculate viewbox distortion */ + this.x /= zoom + this.y /= zoom + this.width = box.width /= zoom + this.height = box.height /= zoom + + /* add the center */ + this.cx = this.x + this.width / 2 + this.cy = this.y + this.height / 2 + +}
\ No newline at end of file |