Editor: Load existing input JSON if it exists
This commit is contained in:
parent
2bc6c4b58b
commit
d12ab839aa
21
js/editor.js
21
js/editor.js
@ -5,11 +5,26 @@ let deckName = window.location.pathname.split('/')[2];
|
|||||||
document.title = "Editor|" + deckName;
|
document.title = "Editor|" + deckName;
|
||||||
|
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
|
// load input json
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.addEventListener("load", () => {
|
||||||
|
// if deck already has input json, load it
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
deckJSON = JSON.parse(xhr.responseText);
|
||||||
|
makeSVGs(deckJSON);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
xhr.open("GET", "deck.input.json");
|
||||||
|
xhr.send();
|
||||||
|
|
||||||
// deck JSON uploader
|
// deck JSON uploader
|
||||||
document.querySelector('#jsonUpload').addEventListener('change', event => {
|
document.querySelector('#jsonUpload').addEventListener('change', event => {
|
||||||
let files = event.target.files;
|
let files = event.target.files;
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.onload = handleUpload;
|
reader.onload = event => {
|
||||||
|
deckJSON = JSON.parse(event.target.result);
|
||||||
|
makeSVGs(deckJSON);
|
||||||
|
};
|
||||||
reader.readAsText(files[0]);
|
reader.readAsText(files[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -57,9 +72,7 @@ function getSVGTemplate(name, callback) {
|
|||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpload(event) {
|
function makeSVGs(deckJSON) {
|
||||||
deckJSON = JSON.parse(event.target.result);
|
|
||||||
|
|
||||||
document.querySelector('#deckName').value = deckJSON.name || "";
|
document.querySelector('#deckName').value = deckJSON.name || "";
|
||||||
document.querySelector('#deckType').value = deckJSON.type || "";
|
document.querySelector('#deckType').value = deckJSON.type || "";
|
||||||
|
|
||||||
|
@ -82,6 +82,9 @@ const server = http.createServer((req, res) => {
|
|||||||
case 'deck.json':
|
case 'deck.json':
|
||||||
sendFileJSON(res, deckName);
|
sendFileJSON(res, deckName);
|
||||||
break;
|
break;
|
||||||
|
case 'deck.input.json':
|
||||||
|
sendFile(res, deckName + ".input.json", 'application/json');
|
||||||
|
break;
|
||||||
case 'upload':
|
case 'upload':
|
||||||
handleUpload(res, req, deckName);
|
handleUpload(res, req, deckName);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user