fix(svg-export): workaround safari incompatiblity

This commit is contained in:
Nico Rehwaldt 2014-05-23 10:58:44 +02:00
parent c672e2e442
commit 6dee60e2ab
2 changed files with 10 additions and 5 deletions

View File

@ -17,9 +17,12 @@ require('./feature/movecanvas');
require('diagram-js/lib/features/selection/Visuals'); require('diagram-js/lib/features/selection/Visuals');
function getSvgNode(diagram) { function getSvgContents(diagram) {
var paper = diagram.get('canvas').getPaper(); var paper = diagram.get('canvas').getPaper();
return paper.node; var outerNode = paper.node.parentNode;
var svg = outerNode.innerHTML;
return svg.replace(/^<svg[^>]>|<\/svg>$/, '');
} }
function initListeners(diagram, listeners) { function initListeners(diagram, listeners) {
@ -131,10 +134,9 @@ Viewer.prototype.saveSVG = function(options, done) {
return done(new Error('no definitions loaded')); return done(new Error('no definitions loaded'));
} }
var svgNode = getSvgNode(this.diagram); var svgContents = getSvgContents(this.diagram);
var svg = svgNode.innerHTML;
svg = SVG_HEADER + svg + SVG_FOOTER; var svg = SVG_HEADER + svgContents + SVG_FOOTER;
done(null, svg); done(null, svg);
}; };

View File

@ -88,6 +88,9 @@ describe('Viewer', function() {
expect(svg.indexOf(expectedStart)).toEqual(0); expect(svg.indexOf(expectedStart)).toEqual(0);
expect(svg.indexOf(expectedEnd)).toEqual(svg.length - expectedEnd.length); expect(svg.indexOf(expectedEnd)).toEqual(svg.length - expectedEnd.length);
// ensure correct rendering of SVG contents
expect(svg.indexOf('undefined')).toBe(-1);
done(); done();
}); });
}); });