Allow downloading input JSONs
This commit is contained in:
parent
6f5ab8b595
commit
2bc6c4b58b
@ -5,7 +5,7 @@
|
|||||||
<title>Editor</title>
|
<title>Editor</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<input id="jsonUpload" type="file"><br>
|
<input id="jsonUpload" type="file"> <button type="button" id="jsonInputDownload">Download input</button> <br>
|
||||||
<form id="deckForm">
|
<form id="deckForm">
|
||||||
<div> <label> Deck Name: <input type="text" id="deckName"></label> </div>
|
<div> <label> Deck Name: <input type="text" id="deckName"></label> </div>
|
||||||
<div>
|
<div>
|
||||||
|
14
js/editor.js
14
js/editor.js
@ -1,7 +1,8 @@
|
|||||||
let deckJSON;
|
let deckJSON;
|
||||||
let selected = 0;
|
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", () => {
|
window.addEventListener("load", () => {
|
||||||
// deck JSON uploader
|
// deck JSON uploader
|
||||||
@ -12,6 +13,17 @@ window.addEventListener("load", () => {
|
|||||||
reader.readAsText(files[0]);
|
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
|
// handle changes to deck editor
|
||||||
document.querySelector('#deckForm').addEventListener('input', event => {
|
document.querySelector('#deckForm').addEventListener('input', event => {
|
||||||
let prop = event.target.id.substring(4).toLowerCase();
|
let prop = event.target.id.substring(4).toLowerCase();
|
||||||
|
Loading…
Reference in New Issue
Block a user