diff --git a/SvgEditor.js b/SvgEditor.js index b5390bab..6f883146 100644 --- a/SvgEditor.js +++ b/SvgEditor.js @@ -39,7 +39,7 @@ function ApplyColorPicker(id , ini_col_hex , fun_var){ function return_str_to_html(str){ - //alert("This is svg image in string format \n This will be posted to server \n " + str) + alert("This is svg image in string format \n This will be posted to server \n " + str) //posting the data to server //document.getElementById("hidden_svg_data").setAttribute("value", escape(str)); @@ -49,4 +49,3 @@ function return_str_to_html(str){ }); } - diff --git a/blank.svg b/blank.svg index b72974e8..688b60cf 100644 --- a/blank.svg +++ b/blank.svg @@ -1,7 +1,7 @@ - diff --git a/blanksvg.js b/blanksvg.js index c9f3ba23..50fa0fc0 100644 --- a/blanksvg.js +++ b/blanksvg.js @@ -1,4 +1,5 @@ SVGDocument = null; + SVGRoot = null; var svgns = "http://www.w3.org/2000/svg"; var d_attr = "" ; var signature_started = 0 ; @@ -46,7 +47,14 @@ function SVGset_stroke_width(val){ function Initialize(LoadEvent) { -SVGDocument = LoadEvent.target.ownerDocument + SVGDocument = LoadEvent.target.ownerDocument; + SVGRoot = SVGDocument.documentElement ; + var Attr={ + "onmouseup":"fun_mouseUP(evt)", + "onmousedown":"fun_mouseDOWN(evt)", + "onmousemove":"fun_mouseMOVE(evt)" + } + assignAttr(SVGRoot,Attr); } @@ -54,7 +62,10 @@ SVGDocument = LoadEvent.target.ownerDocument function fun_mouseUP(evt) { -signature_started = 0 ; + + if (signature_started == 1 ) + { + signature_started = 0 ; switch (current_draw_element) { @@ -73,7 +84,9 @@ signature_started = 0 ; break case "freehandcircle": d_attr = 0 ; - path_num = path_num + 1 ; + + var element = SVGDocument.getElementById("path_" + path_num); + element.parentNode.removeChild(element); create_svg_element_by_json({ "element": "ellipse", @@ -88,9 +101,11 @@ signature_started = 0 ; "stroke-width": current_draw_element_stroke_width } }); + ellipse_num = ellipse_num + 1 ; + break; }//switch - + }//if }//function @@ -193,7 +208,12 @@ function fun_mouseDOWN(evt) "stroke-width": current_draw_element_stroke_width } }); - break + break + case "delete": + var T=evt.target + if(SVGRoot == evt.target ) return ; + T.parentNode.removeChild(T); + break; }//switch @@ -270,6 +290,7 @@ function fun_mouseMOVE(evt) }//function + function min_of(a ,b){ if (a < b ) { return a ;} else {return b ;} @@ -283,28 +304,31 @@ function max_of(a ,b){ function create_svg_element_by_json(data) { var shape = SVGDocument.createElementNS(svgns, data.element); - for (i in data.Attr) { - shape.setAttributeNS(null, i, data.Attr[i]); - } + assignAttr(shape, data.Attr); SVGDocument.documentElement.appendChild(shape); }//function +function assignAttr(Node,Attr){ + for (i in Attr) { + Node.setAttributeNS(null, i, Attr[i]); + } +}//function - function SVGclear_svg() - { - for(var i=1; i \ + \n" + str = str + SvgToString(SVGRoot , 0); + top.return_str_to_html(str); +} - var str = " \ - \n \ \n "; - - for(var i=1; i" - - top.return_str_to_html(str); - - } - diff --git a/svg-editor.html b/svg-editor.html index b57aa3fe..911338b3 100644 --- a/svg-editor.html +++ b/svg-editor.html @@ -30,10 +30,11 @@