Skip to content

Commit

Permalink
Merge pull request #5 from thekuwayama/download_button
Browse files Browse the repository at this point in the history
feat: add download button
  • Loading branch information
thekuwayama authored Nov 16, 2024
2 parents d513b1f + d6265c3 commit ef12aa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions matter_qrcode_generator_wasm/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<div></div>
<div>
<button id="print" type="button">print</button>
<button id="download" type="button" style="display:none">download</button>
</div>
<div></div>

Expand Down
18 changes: 16 additions & 2 deletions matter_qrcode_generator_wasm/www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import init, {do_print_qr} from '../../pkg/matter_qrcode_generator_wasm.js'
import '../css/style.css'

// function
export function print_qr() {
export function printQR() {
init().then(() => {
const vid = parseInt(document.getElementById('vid').value)
const pid = parseInt(document.getElementById('pid').value)
Expand All @@ -27,8 +27,22 @@ export function print_qr() {
}

document.getElementById('qr').innerHTML = qr
document.getElementById('download').style.display = ''
})
}

export function downloadSVG() {
const svg = document.getElementById('qr').innerHTML
const blob = new Blob([svg.toString()])
const a = document.createElement('a')
a.download = 'qr.svg'
a.href = window.URL.createObjectURL(blob)

document.body.appendChild(a)
a.click()
a.remove()
}

// init
document.getElementById('print').onclick = print_qr
document.getElementById('print').onclick = printQR
document.getElementById('download').onclick = downloadSVG

0 comments on commit ef12aa2

Please sign in to comment.