Fix image edit not working in Chrome

This commit is contained in:
Adam Goldsmith 2017-10-11 22:53:29 -04:00
parent 9b66833b8b
commit 89f6e0d638

View File

@ -51,17 +51,8 @@ window.addEventListener("load", () => {
// handle changes to card editor // handle changes to card editor
document.querySelector('#cardForm').addEventListener('input', event => { document.querySelector('#cardForm').addEventListener('input', event => {
let deck = document.querySelector('#deck');
let prop = event.target.id.substring(5); let prop = event.target.id.substring(5);
if (prop === "image") { if (prop !== "count") {
let files = event.target.files;
let reader = new FileReader();
reader.onload = e => {
selected.svg.querySelector('#' + prop).setAttribute("href", e.target.result);
};
reader.readAsDataURL(files[0]);
}
else if (prop !== "count") {
wrapSVGText(selected.svg.querySelector('#' + prop), wrapSVGText(selected.svg.querySelector('#' + prop),
String(event.target.value)); String(event.target.value));
} }
@ -72,6 +63,21 @@ window.addEventListener("load", () => {
delete selected.json[prop]; delete selected.json[prop];
} }
}); });
// chrome doesn't seem to send input event on file select
document.querySelector('#cardForm').addEventListener('change', event => {
let prop = event.target.id.substring(5);
if (prop === "image") {
let files = event.target.files;
let reader = new FileReader();
reader.onload = e => {
selected.svg.querySelector('#' + prop)
.setAttributeNS("http://www.w3.org/1999/xlink", "href", e.target.result);
selected.json[prop] = e.target.result;
};
reader.readAsDataURL(files[0]);
}
});
}); });
function downloadFile(file, name) { function downloadFile(file, name) {