diff options
Diffstat (limited to 'src/event.js')
-rwxr-xr-x | src/event.js | 31 |
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 |