From 9b75362f3e5fc5c622b89dc4a000d57e5a9ebf2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 1 Nov 2013 18:27:20 +0100 Subject: [PATCH] Always respect options.asString --- src/svg/SVGExport.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/svg/SVGExport.js b/src/svg/SVGExport.js index 11ccc42a..0ca70c42 100644 --- a/src/svg/SVGExport.js +++ b/src/svg/SVGExport.js @@ -348,28 +348,30 @@ new function() { } function exportDefinitions(node, options) { - if (!definitions) - return node; - // We can only use svg nodes as defintion containers. Have the loop - // 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 svg = node.nodeName.toLowerCase() === 'svg' && node, + var svg = node, defs = null; - for (var i in definitions.svgs) { - // 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); + if (definitions) { + // We can only use svg nodes as defintion containers. Have the loop + // 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... + svg = node.nodeName.toLowerCase() === 'svg' && node; + for (var i in definitions.svgs) { + // 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); } - defs = svg.insertBefore(createElement('defs'), svg.firstChild); + defs.appendChild(definitions.svgs[i]); } - defs.appendChild(definitions.svgs[i]); + // Clear definitions at the end of export + definitions = null; } - // Clear definitions at the end of export - definitions = null; return options.asString ? new XMLSerializer().serializeToString(svg) : svg;