aboutsummaryrefslogtreecommitdiffstats
path: root/src/event.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-06-11 15:27:07 +0200
committerwout <wout@impinc.co.uk>2014-06-11 15:27:07 +0200
commite3a0f3a887a398a87356f63253830e1baf67823e (patch)
treed2b13c0dc0b4d40270cda7e1968860325d6c49b8 /src/event.js
parent791f4368403571d5e824d91f3562c63baae356a8 (diff)
downloadsvg.js-e3a0f3a887a398a87356f63253830e1baf67823e.tar.gz
svg.js-e3a0f3a887a398a87356f63253830e1baf67823e.zip
Bumped to version 1.0.0-rc.7
Look at change log for full overview of changes.
Diffstat (limited to 'src/event.js')
-rwxr-xr-xsrc/event.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/event.js b/src/event.js
index 73e3ba5..885eab8 100755
--- a/src/event.js
+++ b/src/event.js
@@ -1,8 +1,4 @@
-// ### Manage events on elements
-
-// rect.click(function() {
-// this.fill({ color: '#f06' })
-// })
+// Add events to elements
;[ 'click'
, 'dblclick'
, 'mousedown'
@@ -31,20 +27,23 @@
})
+// Initialize events stack
+SVG.events = {}
+
+// Event constructor
+SVG.registerEvent = function(event) {
+ if (!SVG.events[event])
+ SVG.events[event] = new Event(event)
+}
+
// 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)
+ node.addEventListener(event, listener.bind(node.instance || node), false)
}
// 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)
+ node.removeEventListener(event, listener.bind(node.instance || node), false)
}
//
@@ -61,4 +60,10 @@ SVG.extend(SVG.Element, {
return this
}
+ // Fire given event
+, fire: function(event) {
+ this.node.dispatchEvent(SVG.events[event])
+
+ return this
+ }
}) \ No newline at end of file