diff --git a/editor/svg-editor.js b/editor/svg-editor.js index b9b08597..bd5dec5a 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -2092,7 +2092,12 @@ function svg_edit_setup() { // var revnums = "svg-editor.js ($Rev$) "; // revnums += svgCanvas.getVersion(); // $('#copyright')[0].setAttribute("title", revnums); - + var loc = document.location.href; + if(loc.indexOf('?source=') != -1) { + var pre = '?source=data:image/svg+xml;base64,'; + var src = loc.substring(loc.indexOf(pre) + pre.length); + svgCanvas.setSvgString(Utils.decode64(src)); + } return svgCanvas; }; diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index d046e6f1..7aabb6a3 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -5994,6 +5994,39 @@ var Utils = { return output.join(''); }, + "decode64" : function(input) { + if(window.atob) return window.atob(input); + var output = new StringMaker(); + var chr1, chr2, chr3; + var enc1, enc2, enc3, enc4; + var i = 0; + + // remove all characters that are not A-Z, a-z, 0-9, +, /, or = + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + enc1 = keyStr.indexOf(input.charAt(i++)); + enc2 = keyStr.indexOf(input.charAt(i++)); + enc3 = keyStr.indexOf(input.charAt(i++)); + enc4 = keyStr.indexOf(input.charAt(i++)); + + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + + output.append(String.fromCharCode(chr1)); + + if (enc3 != 64) { + output.append(String.fromCharCode(chr2)); + } + if (enc4 != 64) { + output.append(String.fromCharCode(chr3)); + } + } + + return output.toString(); + }, + // based on http://phpjs.org/functions/utf8_encode:577 // codedread:does not seem to work with webkit-based browsers on OSX "encodeUTF8": function(input) {