From 2bc6c4b58bf29909854cbc3cd5ace2933d2e325a Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sun, 8 Oct 2017 17:46:22 -0400 Subject: [PATCH] Allow downloading input JSONs --- html/editor.html | 2 +- js/editor.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/html/editor.html b/html/editor.html index 4f6a44f..b7c4aa8 100644 --- a/html/editor.html +++ b/html/editor.html @@ -5,7 +5,7 @@ Editor -
+
diff --git a/js/editor.js b/js/editor.js index 8929eb8..260dacc 100644 --- a/js/editor.js +++ b/js/editor.js @@ -1,7 +1,8 @@ let deckJSON; let selected = 0; +let deckName = window.location.pathname.split('/')[2]; -document.title = "Editor|" + window.location.pathname.split('/')[2]; +document.title = "Editor|" + deckName; window.addEventListener("load", () => { // deck JSON uploader @@ -12,6 +13,17 @@ window.addEventListener("load", () => { reader.readAsText(files[0]); }); + // download input JSON + document.querySelector('#jsonInputDownload').addEventListener('click', () => { + let dl = document.createElement('a'); + dl.setAttribute('href', 'data:application/json;charset=utf-8,' + + encodeURIComponent(JSON.stringify(deckJSON))); + dl.setAttribute('download', deckName + '.input.json'); + document.body.appendChild(dl); + dl.click(); + document.body.removeChild(dl); + }); + // handle changes to deck editor document.querySelector('#deckForm').addEventListener('input', event => { let prop = event.target.id.substring(4).toLowerCase();