Allow for downloading the input json from the editor
This commit is contained in:
parent
ae1517a717
commit
fe1d2ecd4a
@ -8,7 +8,8 @@
|
||||
<body>
|
||||
<div>
|
||||
<button type="button" id="saveButton">Save Deck</button>
|
||||
<button type="button" id="jsonInputDownload">Download JSON</button>
|
||||
<button type="button" id="jsonInputDownload">Download Input JSON</button>
|
||||
<button type="button" id="outputDownload">Download Tabletop Output JSON</button>
|
||||
</div>
|
||||
<div>
|
||||
<label> Upload JSON: WARNING: WILL CLEAR DECK
|
||||
|
30
js/editor.js
30
js/editor.js
@ -26,15 +26,18 @@ window.addEventListener("load", () => {
|
||||
document.querySelector('#saveButton').addEventListener('click', upload);
|
||||
|
||||
// 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);
|
||||
});
|
||||
document.querySelector('#jsonInputDownload').addEventListener(
|
||||
'click',
|
||||
() => downloadFile('data:application/json;charset=utf-8,' +
|
||||
encodeURIComponent(JSON.stringify(deckJSON)),
|
||||
deckName + '.input.json'));
|
||||
|
||||
// download input JSON
|
||||
document.querySelector('#outputDownload').addEventListener(
|
||||
'click',
|
||||
() => downloadFile('deck.json',
|
||||
deckName + '.json'));
|
||||
|
||||
|
||||
// handle changes to deck editor
|
||||
document.querySelector('#deckForm').addEventListener('input', event => {
|
||||
@ -67,6 +70,15 @@ window.addEventListener("load", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function downloadFile(file, name) {
|
||||
let dl = document.createElement('a');
|
||||
dl.setAttribute('href', file);
|
||||
dl.setAttribute('download', name);
|
||||
document.body.appendChild(dl);
|
||||
dl.click();
|
||||
document.body.removeChild(dl);
|
||||
}
|
||||
|
||||
function getJSON(filename, callback) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener("load", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user