From 5771e91e137396ad0dc09666b24d157160c195f1 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Tue, 13 Oct 2009 05:41:32 +0000 Subject: [PATCH] Fix serialization of xml:space attribute. Restore copying of text elements. git-svn-id: http://svg-edit.googlecode.com/svn/trunk@814 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 5ecb72a2..34365832 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -555,7 +555,7 @@ function BatchCommand(text) { var handle = svgroot.suspendRedraw(suspendLength); for (i in attrs) { - var ns = (i.substr(0,4) == "xml:" ? "http://www.w3.org/XML/1998/namespace" : null); + var ns = (i.substr(0,4) == "xml:" ? xmlns : null); node.setAttributeNS(ns, i, attrs[i]); } @@ -611,6 +611,7 @@ function BatchCommand(text) { var container = c; var svgns = "http://www.w3.org/2000/svg"; var xlinkns = "http://www.w3.org/1999/xlink"; + var xmlns = "http://www.w3.org/XML/1998/namespace"; var idprefix = "svg_"; var svgdoc = c.ownerDocument; var svgroot = svgdoc.createElementNS(svgns, "svg"); @@ -904,12 +905,15 @@ function BatchCommand(text) { out.push(" "); // map various namespaces to our fixed namespace prefixes // TODO: put this into a map and do a look-up instead of if-else - if (attr.namespaceURI == 'http://www.w3.org/1999/xlink') { + if (attr.namespaceURI == xlinkns) { out.push('xlink:'); } else if(attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' && attr.localName != 'xmlns') { out.push('xmlns:'); } + else if(attr.namespaceURI == xmlns) { + out.push('xml:'); + } out.push(attr.localName); out.push("=\""); out.push(attr.nodeValue); out.push("\""); } @@ -4538,7 +4542,8 @@ function BatchCommand(text) { // manually create a copy of the element var new_el = document.createElementNS(svgns, el.nodeName); $.each(el.attributes, function(i, attr) { - var ns = attr.nodeName == 'href'?xlinkns:null; + var ns = attr.nodeName == 'href' ? xlinkns : + attr.prefix == "xml" ? xmlns : null; new_el.setAttributeNS(ns, attr.nodeName, attr.nodeValue); }); // set the copied element's new id