summaryrefslogtreecommitdiffstats
path: root/src/rbox.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-05-28 20:58:52 +0100
committerwout <wout@impinc.co.uk>2013-05-28 20:58:52 +0100
commitc7df993012b3c0e8cfee75313041c3c64ad9b9e1 (patch)
tree5b4358a6c029d5a1763b939e5b60d300f7a4a124 /src/rbox.js
parent00532a5e2d547c4761aa888c9bda2e94ee310046 (diff)
downloadsvg.js-c7df993012b3c0e8cfee75313041c3c64ad9b9e1.tar.gz
svg.js-c7df993012b3c0e8cfee75313041c3c64ad9b9e1.zip
Added merge() to SVG.BBox
Diffstat (limited to 'src/rbox.js')
-rw-r--r--src/rbox.js60
1 files changed, 35 insertions, 25 deletions
diff --git a/src/rbox.js b/src/rbox.js
index 02405b0..5eb474f 100644
--- a/src/rbox.js
+++ b/src/rbox.js
@@ -1,32 +1,42 @@
// 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) {
+ var e, zoom
+ , box = {}
+
+ /* initialize zero box */
+ this.x = 0
+ this.y = 0
+ this.width = 0
+ this.height = 0
+
+ if (element) {
+ 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
- }
-
- /* 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
+
+ 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
+ }
}
}