diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 3917917d..8ed64f3b 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -22,7 +22,7 @@ TODOS 1. JSDoc */ - +var saveAs; (function() { if (window.svgEditor) { @@ -396,7 +396,7 @@ TODOS * opts.open's responsibilities are: * - invoke a file chooser dialog in 'open' mode * - let user pick a SVG file - * - calls setCanvas.setSvgString() with the string contents of that file + * - calls svgCanvas.setSvgString() with the string contents of that file * opts.save's responsibilities are: * - accept the string contents of the current document * - invoke a file chooser dialog in 'save' mode @@ -1079,41 +1079,46 @@ TODOS }; // Export global for use by jsPDF - saveAs = function (blob, options) { - var blobUrl = URL.createObjectURL(blob); - try { - // This creates a bookmarkable data URL, - // but it doesn't currently work in - // Firefox, and although it works in Chrome, - // Chrome doesn't make the full "data:" URL - // visible unless you right-click to "Inspect - // element" and then right-click on the element - // to "Copy link address". - var xhr = new XMLHttpRequest(); - xhr.responseType = 'blob'; - xhr.onload = function() { - var recoveredBlob = xhr.response; - var reader = new FileReader(); - reader.onload = function() { - var blobAsDataUrl = reader.result; - exportWindow.location.href = blobAsDataUrl; + if (!saveAs) { + saveAs = function (blob, options) { + var blobUrl = URL.createObjectURL(blob); + try { + // This creates a bookmarkable data URL, + // but it doesn't currently work in + // Firefox, and although it works in Chrome, + // Chrome doesn't make the full "data:" URL + // visible unless you right-click to "Inspect + // element" and then right-click on the element + // to "Copy link address". + var xhr = new XMLHttpRequest(); + xhr.responseType = 'blob'; + xhr.onload = function() { + var recoveredBlob = xhr.response; + var reader = new FileReader(); + reader.onload = function() { + var blobAsDataUrl = reader.result; + exportWindow.location.href = blobAsDataUrl; + }; + reader.readAsDataURL(recoveredBlob); }; - reader.readAsDataURL(recoveredBlob); - }; - xhr.open('GET', blobUrl); - xhr.send(); - } - catch (e) { - exportWindow.location.href = blobUrl; - } - }; + xhr.open('GET', blobUrl); + xhr.send(); + } + catch (e) { + exportWindow.location.href = blobUrl; + } + }; + } var exportHandler = function(win, data) { var issues = data.issues, type = data.type || 'PNG', + exportWindowName = data.exportWindowName, dataURLType = (type === 'ICO' ? 'BMP' : type).toLowerCase(); - exportWindow = window.open('', data.exportWindowName); // A hack to get the window via JSON-able name without opening a new one + if (exportWindowName) { + exportWindow = window.open('', exportWindowName); // A hack to get the window via JSON-able name without opening a new one + } if (!$('#export_canvas').length) { $('', {id: 'export_canvas'}).hide().appendTo('body'); } @@ -3981,8 +3986,8 @@ TODOS var all_tools = ''; var cur_class = 'tool_button_current'; - $.each(toolnames, function(i,item) { - all_tools += '#tool_' + item + (i == toolnames.length-1 ? ',' : ''); + $.each(toolnames, function(i, item) { + all_tools += (i ? ',' : '') + '#tool_' + item; }); $(all_tools).mousedown(function() {