aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-06-17 15:55:32 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-06-17 15:55:32 +0200
commit0d6459729c2508d2631894b004d74961fe99d334 (patch)
treee8b2ec0b40c48f72e385efc8b2f8c29cdd2c20f4 /src/event.js
parent71c984a986e1c0980ce0a6eb5626dda989cfa428 (diff)
downloadsvg.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-xsrc/event.js20
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
}