summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-09-03 15:24:24 +0200
committerwout <wout@impinc.co.uk>2014-09-03 15:24:24 +0200
commit17e15d57d8eb2cb20cc72abcf1bd5bb1bbd39e49 (patch)
treed06f213fdf3eb52d35b3f8069dc4f6733795fa3d /src
parent69da2d385450daa158d75ebe59449cc044ec8022 (diff)
downloadsvg.js-17e15d57d8eb2cb20cc72abcf1bd5bb1bbd39e49.tar.gz
svg.js-17e15d57d8eb2cb20cc72abcf1bd5bb1bbd39e49.zip
Fixed bug in event detaching
Diffstat (limited to 'src')
-rwxr-xr-xsrc/boxes.js23
-rwxr-xr-xsrc/event.js37
2 files changed, 42 insertions, 18 deletions
diff --git a/src/boxes.js b/src/boxes.js
index 0b90f60..6451be8 100755
--- a/src/boxes.js
+++ b/src/boxes.js
@@ -53,13 +53,14 @@ SVG.TBox = SVG.invent({
var t = element.ctm().extract()
, box = element.bbox()
- // x and y including transformations
- this.x = box.x + t.x
- this.y = box.y + t.y
-
// width and height including transformations
this.width = box.width * t.scaleX
this.height = box.height * t.scaleY
+
+ // x and y including transformations
+ box = element.rbox()
+ this.x = box.x
+ this.y = box.y
}
// add center, right and bottom
@@ -110,18 +111,18 @@ SVG.RBox = SVG.invent({
this.y -= e.y() || 0
}
}
+
+ // recalculate viewbox distortion
+ this.width = box.width /= zoom
+ this.height = box.height /= zoom
}
- // recalculate viewbox distortion
- this.width = box.width /= zoom
- this.height = box.height /= zoom
-
+ // add center, right and bottom
+ fullBox(this)
+
// offset by window scroll position, because getBoundingClientRect changes when window is scrolled
this.x += window.scrollX
this.y += window.scrollY
-
- // add center, right and bottom
- fullBox(this)
}
// define Parent
diff --git a/src/event.js b/src/event.js
index 3f7e656..2855afa 100755
--- a/src/event.js
+++ b/src/event.js
@@ -42,11 +42,12 @@ SVG.on = function(node, event, listener) {
// create listener
var l = listener.bind(node.instance || node)
- // ensure node reference
- SVG.listeners[node] = SVG.listeners[node] || {}
+ // ensure reference objects
+ SVG.listeners[node] = SVG.listeners[node] || {}
+ SVG.listeners[node][event] = SVG.listeners[node][event] || {}
// reference listener
- SVG.listeners[node][listener] = l
+ SVG.listeners[node][event][listener] = l
// add listener
node.addEventListener(event, l, false)
@@ -54,11 +55,33 @@ SVG.on = function(node, event, listener) {
// Add event unbinder in the SVG namespace
SVG.off = function(node, event, listener) {
- // remove listener
- node.removeEventListener(event, SVG.listeners[node][listener], false)
+ if (listener) {
+ // remove listener reference
+ if (SVG.listeners[node] && SVG.listeners[node][event]) {
+ // remove listener
+ node.removeEventListener(event, SVG.listeners[node][event][listener], false)
- // remove listener reference
- delete SVG.listeners[node][listener]
+ delete SVG.listeners[node][event][listener]
+ }
+
+ } else if (event) {
+ // remove all listeners for the event
+ if (SVG.listeners[node][event]) {
+ for (listener in SVG.listeners[node][event])
+ SVG.off(node, event, listener)
+
+ delete SVG.listeners[node][event]
+ }
+
+ } else {
+ // remove all listeners on a given node
+ if (SVG.listeners[node]) {
+ for (event in SVG.listeners[node])
+ SVG.off(node, event)
+
+ delete SVG.listeners[node]
+ }
+ }
}
//