Removed dependency on svgcanvas.svg by creating the SVG element via javascript

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@48 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Vidar Hokstad
2009-06-07 00:17:21 +00:00
parent 8a55732a30
commit d6057f0674
4 changed files with 48 additions and 53 deletions

View File

@@ -1,19 +1,19 @@
var svgcanvas = null;
function svgCanvasInit(event) {
svgcanvas = new SvgCanvas(event.target.ownerDocument);
svgcanvas.setup(event);
parent.SvgCanvas = svgcanvas;
}
function SvgCanvas(doc)
function SvgCanvas(c)
{
// private members
var svgdoc = doc;
var svgroot = svgdoc.documentElement;
var container = c;
var svgns = "http://www.w3.org/2000/svg";
var svgdoc = c.ownerDocument;
var svgroot = svgdoc.createElementNS(svgns, "svg");
svgroot.setAttribute("width",640);
svgroot.setAttribute("height",480);
svgroot.setAttributeNS(null,"id","svgroot");
container.appendChild(svgroot);
var d_attr = null;
var started = false;
var obj_num = 1;
@@ -72,7 +72,7 @@ function SvgCanvas(doc)
var shape = svgdoc.createElementNS(svgns, data.element);
assignAttributes(shape, data.attr);
cleanupElement(shape);
svgdoc.documentElement.appendChild(shape);
svgroot.appendChild(shape);
return shape;
}
@@ -120,10 +120,10 @@ function SvgCanvas(doc)
// public events
this.mouseDown = function(evt)
var mouseDown = function(evt)
{
var x = evt.pageX;
var y = evt.pageY;
var x = evt.pageX - container.offsetLeft;
var y = evt.pageY - container.offsetTop;
switch (current_mode) {
case "select":
started = true;
@@ -258,12 +258,11 @@ function SvgCanvas(doc)
}
}
this.mouseMove = function(evt)
var mouseMove = function(evt)
{
if (!started) return;
var x = evt.pageX;
var y = evt.pageY;
var x = evt.pageX - container.offsetLeft;
var y = evt.pageY - container.offsetTop;
var shape = svgdoc.getElementById(getId());
switch (current_mode)
{
@@ -311,7 +310,7 @@ function SvgCanvas(doc)
}
}
this.mouseUp = function(evt)
var mouseUp = function()
{
if (!started) return;
@@ -496,13 +495,9 @@ function SvgCanvas(doc)
events[event] = f;
}
this.setup = function(evt) {
assignAttributes(svgroot, {
"onmouseup": "svgcanvas.mouseUp(evt)",
"onmousedown": "svgcanvas.mouseDown(evt)",
"onmousemove": "svgcanvas.mouseMove(evt)"
});
}
$(container).mouseup(mouseUp);
$(container).mousedown(mouseDown);
$(container).mousemove(mouseMove);
this.saveHandler = function(svg) {
alert(svg);