aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-01-09 20:22:00 +0100
committerwout <wout@impinc.co.uk>2013-01-09 20:22:00 +0100
commit999f4b8b44a529fe2af2f32f21e76804c8a85ea6 (patch)
tree67d9506b5b70dd34cec447b0037685367e4863ea /src/event.js
parent145f7e09035c8503ec7b408fd7313f09f54d5bd8 (diff)
downloadsvg.js-999f4b8b44a529fe2af2f32f21e76804c8a85ea6.tar.gz
svg.js-999f4b8b44a529fe2af2f32f21e76804c8a85ea6.zip
Added event listeners to event module
Diffstat (limited to 'src/event.js')
-rw-r--r--src/event.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/event.js b/src/event.js
index a9b1cfc..8e485b6 100644
--- a/src/event.js
+++ b/src/event.js
@@ -26,4 +26,37 @@
return this;
};
+
});
+
+// Add event binder in the SVG namespace
+SVG.on = function(node, event, listener) {
+ if (node.addEventListener)
+ node.addEventListener(event, listener, false);
+ else
+ node.attachEvent('on' + event, listener);
+};
+
+// Add event unbinder in the SVG namespace
+SVG.off = function(node, event, listener) {
+ if (node.removeEventListener)
+ node.removeEventListener(event, listener, false);
+ else
+ node.detachEvent('on' + event, listener);
+};
+
+//
+SVG.extend(SVG.Element, {
+ // Bind given event to listener
+ on: function(event, listener) {
+ SVG.on(this.node, event, listener);
+
+ return this;
+ },
+ // Unbind event from listener
+ off: function(event, listener) {
+ SVG.off(this.node, event, listener);
+
+ return this;
+ }
+}); \ No newline at end of file