From 4d33fb925e70574a1585ef4cd2324c10af3fcccb Mon Sep 17 00:00:00 2001 From: Vidar Hokstad Date: Sat, 6 Jun 2009 18:34:42 +0000 Subject: [PATCH] Added support for plugging in event handlers - will allow the wave gadget to receive state notifications without any wave specific code in the editor itself git-svn-id: http://svg-edit.googlecode.com/svn/trunk@43 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 6ec24d3b..4c19c24e 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -32,12 +32,19 @@ function SvgCanvas(doc) var freehand_min_y = null; var freehand_max_y = null; var selected = null; + var events = {}; // private functions var getId = function() { return "svg_"+obj_num; } + var call = function(event, arg) { + if (events[event]) { + return events[event](this,arg); + } + } + var assignAttributes = function(node, attrs) { for (i in attrs) { node.setAttributeNS(null, i, attrs[i]); @@ -66,6 +73,7 @@ function SvgCanvas(doc) assignAttributes(shape, data.attr); cleanupElement(shape); svgdoc.documentElement.appendChild(shape); + call("changed",shape); } var svgToString = function(elem, indent) { @@ -393,6 +401,7 @@ function SvgCanvas(doc) } else if (element != null) { element.setAttribute("opacity", current_opacity); cleanupElement(element); + call("changed",element); } } @@ -482,6 +491,10 @@ function SvgCanvas(doc) current_stroke_opacity = val; } + this.bind = function(event, f) { + events[event] = f; + } + this.setup = function(evt) { assignAttributes(svgroot, { "onmouseup": "svgcanvas.mouseUp(evt)",