Skip to content

Commit

Permalink
Add default image when invalid content is pasted
Browse files Browse the repository at this point in the history
  • Loading branch information
nmarsceau committed May 16, 2024
1 parent 7704d81 commit 8a7305d
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 10 deletions.
8 changes: 4 additions & 4 deletions _site/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ body {
}

.icon.button#upload::before {
background: url(../svg/upload.svg) center/70% no-repeat, var(--yellow);
background: url(../images/upload.svg) center/70% no-repeat, var(--yellow);
}

.icon.button#clear::before {
background: url(../svg/clear.svg) center/130% no-repeat, var(--yellow);
background: url(../images/clear.svg) center/130% no-repeat, var(--yellow);
}

.icon.button#copy::before {
background: url(../svg/copy.svg) center/80% no-repeat, var(--yellow);
background: url(../images/copy.svg) center/80% no-repeat, var(--yellow);
}

.icon.button#download::before {
background: url(../svg/download.svg) center/70% no-repeat, var(--yellow);
background: url(../images/download.svg) center/70% no-repeat, var(--yellow);
}

.icon.button::after {
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added _site/assets/images/picard.webp
Binary file not shown.
File renamed without changes
4 changes: 4 additions & 0 deletions _site/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class App {
this.img.addEventListener('load', () => { this.drawImage() })
}

setDefaultImage() {
this.img.src = "./assets/images/picard.webp"
}

setImageFromFile(file) {
const reader = new FileReader()
reader.readAsDataURL(file)
Expand Down
4 changes: 3 additions & 1 deletion _site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
document.addEventListener('paste', (event) => {
if (event.clipboardData.files.length > 0) {
app.setImageFromFile(event.clipboardData.files[0])
}
} else {
app.setDefaultImage()
}
})
document.querySelector('#download').addEventListener('click', () => { app.download() })</script></body></html>
8 changes: 4 additions & 4 deletions src/_includes/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ body {
}

.icon.button#upload::before {
background: url(../svg/upload.svg) center/70% no-repeat, var(--yellow);
background: url(../images/upload.svg) center/70% no-repeat, var(--yellow);
}

.icon.button#clear::before {
background: url(../svg/clear.svg) center/130% no-repeat, var(--yellow);
background: url(../images/clear.svg) center/130% no-repeat, var(--yellow);
}

.icon.button#copy::before {
background: url(../svg/copy.svg) center/80% no-repeat, var(--yellow);
background: url(../images/copy.svg) center/80% no-repeat, var(--yellow);
}

.icon.button#download::before {
background: url(../svg/download.svg) center/70% no-repeat, var(--yellow);
background: url(../images/download.svg) center/70% no-repeat, var(--yellow);
}

.icon.button::after {
Expand Down
1 change: 1 addition & 0 deletions src/_includes/assets/images/clear.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/_includes/assets/images/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/_includes/assets/images/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/_includes/assets/images/picard.webp
Binary file not shown.
1 change: 1 addition & 0 deletions src/_includes/assets/images/upload.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/_includes/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class App {
this.img.addEventListener('load', () => { this.drawImage() })
}

setDefaultImage() {
this.img.src = "./assets/images/picard.webp"
}

setImageFromFile(file) {
const reader = new FileReader()
reader.readAsDataURL(file)
Expand Down
4 changes: 3 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
document.addEventListener('paste', (event) => {
if (event.clipboardData.files.length > 0) {
app.setImageFromFile(event.clipboardData.files[0])
}
} else {
app.setDefaultImage()
}
})
document.querySelector('#download').addEventListener('click', () => { app.download() })
</script>
Expand Down

0 comments on commit 8a7305d

Please sign in to comment.