From 3fb99093d6fec345163fce39ec0202a4dbdccea7 Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 17 Jun 2023 21:49:35 -0400 Subject: init --- demo.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 demo.js (limited to 'demo.js') diff --git a/demo.js b/demo.js new file mode 100644 index 0000000..5365ad3 --- /dev/null +++ b/demo.js @@ -0,0 +1,68 @@ + +const htmlOuter = inner => ` + + + + + + Photo Album + + + +${inner} + + +`; + +let images = []; + +function download() { + const elHtml = preview.innerHTML; + const link = document.createElement('a'); + const mimeType = 'text/plain'; + link.download = `${(new Date()).toISOString()}-photobook.html`; + link.href = 'data:' + + mimeType + + ';charset=utf-8,' + + encodeURIComponent(htmlOuter(elHtml)); + link.click(); + URL.revokeObjectURL(link.href); +} + +function addimages() { + const files = image.files; + for (let i = 0; i < files.length; i++) { + addimage(files[i]); + } +} + +function renderImages() { + preview.innerHTML = ''; + images.forEach(x => { +// const deleteButton = document.createElement('button'); + x.style.maxHeight = '100%'; + x.style.maxWidth = '100%'; + x.style.paddingTop = '1em'; + preview.appendChild(x) + }); +} + +function addimage(file) { + const img = new Image; + const fr = new FileReader; + fr.onload = () => {img.src = fr.result}; + fr.readAsDataURL(file); + img.onload = () => { + images.push(img); + renderImages(); + } +} + -- cgit v1.2.3