diff --git a/client/index.html b/client/index.html index e4752db..bac1156 100644 --- a/client/index.html +++ b/client/index.html @@ -80,9 +80,7 @@

File Received

Filename
- +
diff --git a/client/scripts/ui.js b/client/scripts/ui.js index 0c15984..96ba911 100644 --- a/client/scripts/ui.js +++ b/client/scripts/ui.js @@ -234,6 +234,7 @@ class ReceiveDialog extends Dialog { window.blop.play(); }); this._filesQueue = []; + this.$previewBox = this.$el.querySelector('.preview') } _nextFile(nextFile) { @@ -266,10 +267,23 @@ class ReceiveDialog extends Dialog { $a.click() return } - if(file.mime.split('/')[0] === 'image'){ - console.log('the file is image'); - this.$el.querySelector('.preview').style.visibility = 'inherit'; - this.$el.querySelector("#img-preview").src = url; + + let mine = file.mime.split('/')[0] + let previewElement = { + image: 'img', + audio: 'audio', + video: 'video' + } + + if(Object.keys(previewElement).indexOf(mine) !== -1){ + console.log('the file is able to preview'); + let element = document.createElement(previewElement[mine]); + element.src = url; + element.controls = true; + element.classList = 'element-preview' + + this.$previewBox.style.visibility = 'inherit'; + this.$previewBox.appendChild(element) } this.$el.querySelector('#fileName').textContent = file.name; @@ -297,8 +311,8 @@ class ReceiveDialog extends Dialog { } hide() { - this.$el.querySelector('.preview').style.visibility = 'hidden'; - this.$el.querySelector("#img-preview").src = ""; + this.$previewBox.style.visibility = 'hidden'; + this.$previewBox.innerHTML = ''; super.hide(); this._dequeueFile(); } diff --git a/client/styles.css b/client/styles.css index 0a9aca9..c3e573d 100644 --- a/client/styles.css +++ b/client/styles.css @@ -717,8 +717,9 @@ x-dialog x-paper { color: var(--text-color); background-color: var(--bg-color-secondary); } -/* Image Preview */ -#img-preview{ +/* Image/Video/Audio Preview */ +.element-preview { + max-width: 100%; max-height: 50vh; margin: auto; display: block;