Preserve comments when editing SVG source

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@315 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-07-13 03:23:58 +00:00
parent 5ce77bca33
commit 5e15483254
2 changed files with 19 additions and 17 deletions

View File

@ -410,11 +410,10 @@ function svg_edit_setup() {
svgCanvas.redo(); svgCanvas.redo();
}; };
// TODO: prevent 'u' from showing up in the textarea
// TODO: properly size the text area during resize // TODO: properly size the text area during resize
// TODO: properly handle error conditions (error msg dialog) // TODO: properly handle error conditions (error msg dialog)
// TODO: prevent @style showing up on the svg element // TODO: prevent @style showing up on the svg element
// TODO: create new button or Source Editor // TODO: create new button for Source Editor
var showSourceEditor = function(){ var showSourceEditor = function(){
if (editingsource) return; if (editingsource) return;
editingsource = true; editingsource = true;
@ -437,6 +436,9 @@ function svg_edit_setup() {
if (svgCanvas.setSvgString($('#svg_source_textarea').val())) { if (svgCanvas.setSvgString($('#svg_source_textarea').val())) {
console.log('yo'); console.log('yo');
} }
else {
alert('There were parsing errors in your SVG source.\nReverting back to original SVG source.');
}
$('#svg_source_editor').hide(); $('#svg_source_editor').hide();
editingsource = false; editingsource = false;
$('#svg_source_textarea').blur(); $('#svg_source_textarea').blur();
@ -527,18 +529,7 @@ function svg_edit_setup() {
$(document).bind('keydown', {combi:'y', disableInInput: true}, clickRedo); $(document).bind('keydown', {combi:'y', disableInInput: true}, clickRedo);
$(document).bind('keydown', {combi:'u', disableInInput: true}, function(evt){showSourceEditor();evt.preventDefault();}); $(document).bind('keydown', {combi:'u', disableInInput: true}, function(evt){showSourceEditor();evt.preventDefault();});
$(document).bind('keydown', {combi:'esc', disableInInput: false}, hideSourceEditor); $(document).bind('keydown', {combi:'esc', disableInInput: false}, hideSourceEditor);
// temporary binding to test setSvgString()
/*
$(document).bind('keydown', {combi:'t', disableInInput: true}, function() {
if (svgCanvas.setSvgString(
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="foo" width="300" height="200"><bar><knuckle/><head/><rect width="200" height="100" fill="red" /></bar><circle cx="100" cy="100" r="40" fill="green" strike="blue"/><foo/></svg>')) {
updateContextPanel();
var dims = svgCanvas.getResolution();
changeResolution(dims[0],dims[1]);
}
});
*/
var colorPicker = function(elem) { var colorPicker = function(elem) {
var oldbg = elem.css('background'); var oldbg = elem.css('background');
var color = elem.css('background-color'); var color = elem.css('background-color');
@ -684,7 +675,7 @@ function svg_edit_setup() {
function changeResolution(x,y) { function changeResolution(x,y) {
$('#resolution').val(x+'x'+y); $('#resolution').val(x+'x'+y);
$('#svgroot').css( { 'width': x+'px', 'height': y+'px' } ); // $('#svgroot').css( { 'width': x+'px', 'height': y+'px' } );
$('#svgcanvas').css( { 'width': x+'px', 'height': y+'px' } ); $('#svgcanvas').css( { 'width': x+'px', 'height': y+'px' } );
} }

View File

@ -486,6 +486,7 @@ function SvgCanvas(c)
} }
undoStack.push(cmd); undoStack.push(cmd);
undoStackPointer = undoStack.length; undoStackPointer = undoStack.length;
console.log(undoStack);
}; };
// private functions // private functions
@ -617,16 +618,26 @@ function SvgCanvas(c)
{ {
var child = childs.item(i); var child = childs.item(i);
if (child.id == "selectorParentGroup") continue; if (child.id == "selectorParentGroup") continue;
if (child.nodeType == 1) { // element node switch(child.nodeType) {
case 1: // element node
out.push("\n"); out.push("\n");
out.push(svgToString(childs.item(i), indent)); out.push(svgToString(childs.item(i), indent));
} else if (child.nodeType == 3) { // text node break;
case 3: // text node
var str = child.nodeValue.replace(/^\s+|\s+$/g, ""); var str = child.nodeValue.replace(/^\s+|\s+$/g, "");
if (str != "") { if (str != "") {
bOneLine = true; bOneLine = true;
out.push(str + ""); out.push(str + "");
} }
} break;
case 8: // comment
out.push("\n");
out.push(new Array(indent+1).join(" "));
out.push("<!--");
out.push(child.data);
out.push("-->");
break;
} // switch on node type
} }
indent--; indent--;
if (!bOneLine) { if (!bOneLine) {