Skip to content

Commit

Permalink
feature: add download functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
0x04 committed Sep 25, 2024
1 parent db120f1 commit 757b09b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/toolbar-top.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class ToolbarTop extends Toolbar {

setup() {
this.setupBtnCopy()
this.setupBtnDownload()
this.attachSpacer()
this.setupNew()
this.attachSeparator()
Expand Down Expand Up @@ -82,4 +83,30 @@ export class ToolbarTop extends Toolbar {

this.attachItem('btnCopy', btnCopy)
}

setupBtnDownload() {
const btnDownload = document.createElement('button')

btnDownload.classList.add(
'emoji-paint__toolbar-top-btn-download',
'emoji-paint__icon-btn'
)
btnDownload.title = 'Download'
btnDownload.innerText = '⬇️'
btnDownload.addEventListener('click', () => {
const anchor = document.createElement('a')
const data = this.paint.canvas.data.toString()
const blob = new Blob([ data ], { type: 'text/plain' })

anchor.download = 'emoji-paint.txt'
anchor.href = URL.createObjectURL(blob)

document.body.append(anchor)

anchor.click()
anchor.remove()
})

this.attachItem('btnDownload', btnDownload)
}
}

0 comments on commit 757b09b

Please sign in to comment.