From 17e15d57d8eb2cb20cc72abcf1bd5bb1bbd39e49 Mon Sep 17 00:00:00 2001 From: wout Date: Wed, 3 Sep 2014 15:24:24 +0200 Subject: Fixed bug in event detaching --- src/boxes.js | 23 ++++++++++++----------- src/event.js | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 18 deletions(-) (limited to 'src') 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] + } + } } // -- cgit v1.2.3