diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2015-06-17 15:55:32 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2015-06-17 15:55:32 +0200 |
commit | 0d6459729c2508d2631894b004d74961fe99d334 (patch) | |
tree | e8b2ec0b40c48f72e385efc8b2f8c29cdd2c20f4 /src/event.js | |
parent | 71c984a986e1c0980ce0a6eb5626dda989cfa428 (diff) | |
download | svg.js-0d6459729c2508d2631894b004d74961fe99d334.tar.gz svg.js-0d6459729c2508d2631894b004d74961fe99d334.zip |
Events, Spec update, readme
Events can now be detached with only specifying the namespace (`el.off('.namespace')`)
`el.fire()` now accepts event-objects as parameter (like mouseevents)
Diffstat (limited to 'src/event.js')
-rwxr-xr-x | src/event.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/event.js b/src/event.js index 22a6117..451b904 100755 --- a/src/event.js +++ b/src/event.js @@ -69,8 +69,8 @@ SVG.off = function(node, event, listener) { delete SVG.listeners[index][ev][ns || '*'][listener] } - } else if (ns) { - // remove all listeners for the namespaced event + } else if (ns && ev) { + // remove all listeners for a namespaced event if (SVG.listeners[index][ev] && SVG.listeners[index][ev][ns]) { for (listener in SVG.listeners[index][ev][ns]) SVG.off(node, [ev, ns].join('.'), listener) @@ -78,6 +78,16 @@ SVG.off = function(node, event, listener) { delete SVG.listeners[index][ev][ns] } + } else if (ns){ + // remove all listeners for a specific namespace + for(event in SVG.listeners[index]){ + for(namespace in SVG.listeners[index][event]){ + if(ns === namespace){ + SVG.off(node, [event, ns].join('.')) + } + } + } + } else if (ev) { // remove all listeners for the event if (SVG.listeners[index][ev]) { @@ -115,7 +125,11 @@ SVG.extend(SVG.Element, { , fire: function(event, data) { // Dispatch event - this.node.dispatchEvent(new CustomEvent(event, {detail:data})) + if(event instanceof Event){ + this.node.dispatchEvent(event) + }else{ + this.node.dispatchEvent(new CustomEvent(event, {detail:data})) + } return this } |