From e9b482e5611df66f1694c88cbdbdcdcd21ffbe05 Mon Sep 17 00:00:00 2001 From: Mark MacKay Date: Fri, 11 Jun 2021 12:41:47 -0500 Subject: [PATCH] adding load from url --- src/js/Import.js | 2 +- src/js/editor.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/js/Import.js b/src/js/Import.js index c37a737..77b7f73 100644 --- a/src/js/Import.js +++ b/src/js/Import.js @@ -96,7 +96,6 @@ MD.Import = function(){ var reader = new FileReader(); reader.onloadend = function(e) { loadSvgString(e.target.result); - editor.saveCanvas(); editor.canvas.update(true); }; reader.readAsText(f.files[0]); @@ -135,5 +134,6 @@ MD.Import = function(){ this.place = place; this.open = open; + this.loadSvgString = loadSvgString; } \ No newline at end of file diff --git a/src/js/editor.js b/src/js/editor.js index f2fa8dd..41cd0db 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -349,6 +349,25 @@ MD.Editor = function(){ editor.modal.source.open(); } + function loadFromUrl(url, cb){ + if(!cb) cb = function(){/*noop*/}; + $.ajax({ + 'url': url, + 'dataType': 'text', + cache: false, + success: function(str) { + editor.import.loadSvgString(str, cb); + }, + error: function(xhr, stat, err) { + if(xhr.status != 404 && xhr.responseText) { + editor.import.loadSvgString(xhr.responseText, cb); + } else { + $.alert("Unable to load from URL" + ": \n"+err+'', cb); + } + } + }); + } + this.el = el; this.selectedChanged = selectedChanged; this.elementChanged = elementChanged; @@ -387,6 +406,7 @@ MD.Editor = function(){ this.donate = donate; this.source = source; this.saveCanvas = saveCanvas; + this.loadFromUrl = loadFromUrl; this.export = function(){ if(window.canvg) {