Skip to content

Commit

Permalink
Add dropzone for thumbnail picture
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminrobinet committed Apr 9, 2021
1 parent 1c2ea0a commit 05e3ff7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

<div class="py-form-group v-thumb">
<input type="file" class="js-thumbnail-input py-form-file file-video-thumbnail" id="video-thumbnail" name="video-thumbnail" required/>
<label class="py-form-filelabel" for="video-thumbnail">
<label class="py-form-filelabel py-label-video-thumbnail" for="video-thumbnail">
<img src="/" class="video-fileinput-img preview-video-thumbnail"/>
<span class="file-video-dragarea"></span>
<img src="images/illu-video-fileinput.svg" class="file-video-illu" alt="">
Expand Down
23 changes: 23 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const titleInput = document.querySelector('.js-title-input')
const channelThumbnailInput = document.querySelector('.js-channel-thumbnail-input')
const channelNameInput = document.querySelector('.js-channel-name-input')
const randomButton = document.querySelector('#random')
const thumbnailVideoDropzone = document.querySelector('.py-label-video-thumbnail')
const thumbnailInput = document.querySelector('.js-thumbnail-input')
const errorMessageSpan = document.querySelector('#extErrorMessage')
const darkModeBtn = document.querySelector('.js-darkmode-btn')
Expand Down Expand Up @@ -188,6 +189,28 @@ thumbnailInput.addEventListener('change', () => {
}
})

thumbnailVideoDropzone.addEventListener('dragover', (e) => {
e.preventDefault()
})

thumbnailVideoDropzone.addEventListener('drop', (e) => {
e.preventDefault()

if (e.dataTransfer.items.length) {
const file = e.dataTransfer.items[0].getAsFile()
const reader = new FileReader()

reader.addEventListener('load', function () {
// Convert image file to base64 string
videoThumbnail = reader.result
previewVideo.src = reader.result
thumbnailInput.classList.add('loaded')
}, false)

reader.readAsDataURL(file)
}
})

channelThumbnailInput.addEventListener('change', () => {
const file = channelThumbnailInput.files[0]
const reader = new FileReader()
Expand Down

0 comments on commit 05e3ff7

Please sign in to comment.