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
master
Vidar Hokstad 2009-06-06 18:34:42 +00:00
parent d5ba10b166
commit 4d33fb925e
1 changed files with 13 additions and 0 deletions

View File

@ -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)",