aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-02-27 12:12:19 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-02-27 12:12:19 +0100
commit826bb9845ffdbd11be427aad3ffa1f7d4a650eab (patch)
tree2b072b6e24f7a7eb9213c42d152db4cb9dd17d52 /src
parent9569005ce473d614375576ff28a9095b19d94ed0 (diff)
downloadsvg.js-826bb9845ffdbd11be427aad3ffa1f7d4a650eab.tar.gz
svg.js-826bb9845ffdbd11be427aad3ffa1f7d4a650eab.zip
fixed error that listener was strangely defined even if function was called without
Diffstat (limited to 'src')
-rw-r--r--src/event.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/event.js b/src/event.js
index f0d0e0c..6408e88 100644
--- a/src/event.js
+++ b/src/event.js
@@ -56,12 +56,16 @@ SVG.on = function (node, events, listener, binding, options) {
// Add event unbinder in the SVG namespace
SVG.off = function (node, events, listener, options) {
var n = node instanceof SVG.Element ? node.node : node
+ var listenerId
+
if (!n.instance) return
- // make a precheck for a valid listener here to avoid repetition in the loop
- if (listener) {
- if (typeof listener === 'function') listener = listener._svgjsListenerId
- if (!listener) return
+ // listener can be a function or a number
+ if (typeof listener === 'function') {
+ listenerId = listener._svgjsListenerId
+ if (!listenerId) return
+ } else {
+ listenerId = listener
}
var bag = n.instance.events
@@ -71,13 +75,13 @@ SVG.off = function (node, events, listener, options) {
var ns = event && event.split('.')[1]
var namespace
- if (listener) {
+ if (listenerId) {
// remove listener reference
if (bag[ev] && bag[ev][ns || '*']) {
- // remove listener
- n.removeEventListener(ev, bag[ev][ns || '*'][listener], options || false)
+ // removeListener
+ n.removeEventListener(ev, bag[ev][ns || '*'][listenerId], options || false)
- delete bag[ev][ns || '*'][listener]
+ delete bag[ev][ns || '*'][listenerId]
}
} else if (ev && ns) {
// remove all listeners for a namespaced event
@@ -118,6 +122,7 @@ SVG.extend(SVG.Element, {
// Unbind event from listener
off: function (event, listener) {
SVG.off(this.node, event, listener)
+ return this
},
dispatch: function (event, data) {
// Dispatch event