From 1e029fa53674f3134f24bd1d86c3a37e1cff91d2 Mon Sep 17 00:00:00 2001 From: Mark MacKay Date: Sat, 23 Oct 2021 14:26:51 -0500 Subject: [PATCH] load svg with parameter --- src/js/start.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/js/start.js b/src/js/start.js index aa83d30..a65818a 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -32,7 +32,29 @@ const shapeLib = svgCanvas.addExtension.apply(this, ["shapes", MD.Shapelib]); const eyedropper = svgCanvas.addExtension.apply(this, ["eyedropper", MD.Eyedropper]); state.set("canvasId", t("Untitled")); state.set("canvasMode", state.get("canvasMode")); -svgCanvas.setSvgString(state.get("canvasContent")); + +// load from param +console.log(window.location.search) +if (!window.location.search.includes("?load=")) { + svgCanvas.setSvgString(state.get("canvasContent")); +} +else { + + const error = function(err) { + console.log(err); + svgCanvas.setSvgString(state.get("canvasContent")); + } + + const url = utils.findGetParameter("load"); + fetch(url) + .then(r => r.text()) + .then(text => { + if (text.includes("Error response")) return error("Error response"); + svgCanvas.setSvgString(text); + }) + .catch(error); +} + state.set("canvasTitle", svgCanvas.getDocumentTitle()); //editor.paintBox.fill.setPaint(state.get("canvasFill"));