aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-03-01 00:09:17 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-03-01 00:09:17 +0100
commit2eff42ea62f1ff8301000b49eae54cc8c370ee66 (patch)
tree65f72d86d17143ce6976982212ee7fa2a0337d33 /src/event.js
parent2fc54cb89bef303efa9be3dfcd26ff10921deb04 (diff)
downloadsvg.js-2eff42ea62f1ff8301000b49eae54cc8c370ee66.tar.gz
svg.js-2eff42ea62f1ff8301000b49eae54cc8c370ee66.zip
Fixes #323
Diffstat (limited to 'src/event.js')
-rwxr-xr-xsrc/event.js38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/event.js b/src/event.js
index d7a83b2..10585bb 100755
--- a/src/event.js
+++ b/src/event.js
@@ -28,22 +28,24 @@
})
// Initialize listeners stack
-SVG.listeners = {}
+SVG.listeners = []
+SVG.handlerMap = []
// Only kept for consistency of API
SVG.registerEvent = function(){};
// Add event binder in the SVG namespace
SVG.on = function(node, event, listener) {
- // create listener
- var l = listener.bind(node.instance || node)
-
- // ensure reference objects
- SVG.listeners[node] = SVG.listeners[node] || {}
- SVG.listeners[node][event] = SVG.listeners[node][event] || {}
+ // create listener, get object-index
+ var l = listener.bind(node.instance || node)
+ , index = (SVG.handlerMap.indexOf(node) + 1 || SVG.handlerMap.push(node)) - 1
+
+ // ensure valid object
+ SVG.listeners[index] = SVG.listeners[index] || {}
+ SVG.listeners[index][event] = SVG.listeners[index][event] || {}
// reference listener
- SVG.listeners[node][event][listener] = l
+ SVG.listeners[index][event][listener] = l
// add listener
node.addEventListener(event, l, false)
@@ -51,31 +53,33 @@ SVG.on = function(node, event, listener) {
// Add event unbinder in the SVG namespace
SVG.off = function(node, event, listener) {
+ var index = SVG.handlerMap.indexOf(node)
+
if (listener) {
// remove listener reference
- if (SVG.listeners[node] && SVG.listeners[node][event]) {
+ if (index != -1 && SVG.listeners[index][event]) {
// remove listener
- node.removeEventListener(event, SVG.listeners[node][event][listener], false)
+ node.removeEventListener(event, SVG.listeners[index][event][listener], false)
- delete SVG.listeners[node][event][listener]
+ delete SVG.listeners[index][event][listener]
}
} else if (event) {
// remove all listeners for the event
- if (SVG.listeners[node][event]) {
- for (listener in SVG.listeners[node][event])
+ if (SVG.listeners[index][event]) {
+ for (listener in SVG.listeners[index][event])
SVG.off(node, event, listener)
- delete SVG.listeners[node][event]
+ delete SVG.listeners[index][event]
}
} else {
// remove all listeners on a given node
- if (SVG.listeners[node]) {
- for (event in SVG.listeners[node])
+ if (index != -1) {
+ for (event in SVG.listeners[index])
SVG.off(node, event)
- delete SVG.listeners[node]
+ delete SVG.listeners[index]
}
}
}