From f70af7cc02ba9a04a64cd376df14831a9146f4da Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 11 Oct 2017 22:53:29 -0400 Subject: [PATCH] Fix image edit not working in Chrome --- js/editor.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/js/editor.js b/js/editor.js index 0b79e51..1bed972 100644 --- a/js/editor.js +++ b/js/editor.js @@ -51,17 +51,8 @@ window.addEventListener("load", () => { // handle changes to card editor document.querySelector('#cardForm').addEventListener('input', event => { - let deck = document.querySelector('#deck'); 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).setAttribute("href", e.target.result); - }; - reader.readAsDataURL(files[0]); - } - else if (prop !== "count") { + if (prop !== "count") { wrapSVGText(selected.svg.querySelector('#' + prop), String(event.target.value)); } @@ -72,6 +63,21 @@ window.addEventListener("load", () => { 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) {