From d41f79598e719162af3fbcc61f355890bcb32a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 11 Jun 2013 14:26:04 -0700 Subject: [PATCH] Change exportDefinitions() to create an actual container for definitions. --- src/svg/SVGExport.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/svg/SVGExport.js b/src/svg/SVGExport.js index c245ec74..882961c5 100644 --- a/src/svg/SVGExport.js +++ b/src/svg/SVGExport.js @@ -448,8 +448,10 @@ new function() { } function setDefinition(item, node) { + // Have different id ranges per type var type = item._type, id = definitions.ids[type] = (definitions.ids[type] || 0) + 1; + // Give the svg node an ide, and link to it from the item id. node.id = type + '-' + id; definitions.svgs[item._id] = node; } @@ -461,18 +463,24 @@ new function() { // produce one if it's a single item of another type (when calling // #exportSVG() on an item rather than a whole project) // jsdom in Node.js uses uppercase values for nodeName... - var container = node.nodeName.toLowerCase() === 'svg' && node, - firstChild = container ? container.firstChild : node; + var svg = node.nodeName.toLowerCase() === 'svg' && node, + firstChild = svg ? svg.firstChild : node, + defs = null; for (var i in definitions.svgs) { - if (!container) { - container = createElement('svg'); - container.appendChild(node); + // This code is inside the loop so we only create a container if we + // actually have svgs. + if (!defs) { + if (!svg) { + svg = createElement('svg'); + svg.appendChild(node); + } + defs = svg.insertBefore(createElement('defs'), svg.firstChild); } - container.insertBefore(definitions.svgs[i], firstChild); + defs.appendChild(definitions.svgs[i]); } // Clear definitions at the end of export definitions = null; - return container; + return svg; } function exportSVG(item) {