Fix attachment previews for audio/video files
This commit is contained in:
parent
6fe262ceed
commit
1311f7c9ae
4 changed files with 33 additions and 7 deletions
|
@ -18,7 +18,7 @@ var Whisper = Whisper || {};
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
Whisper.AttachmentPreviewView = Backbone.View.extend({
|
Whisper.AttachmentPreviewView = Backbone.View.extend({
|
||||||
className: 'imageAttachment',
|
className: 'attachment-preview',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.template = $('#attachment-preview').html();
|
this.template = $('#attachment-preview').html();
|
||||||
Mustache.parse(this.template);
|
Mustache.parse(this.template);
|
||||||
|
|
|
@ -41,8 +41,8 @@ var Whisper = Whisper || {};
|
||||||
this.$input.click();
|
this.$input.click();
|
||||||
},
|
},
|
||||||
|
|
||||||
addThumb: function(e) {
|
addThumb: function(src) {
|
||||||
this.thumb.src = e.target.result;
|
this.thumb.src = src;
|
||||||
this.$el.find('.paperclip').append(this.thumb.render().el);
|
this.$el.find('.paperclip').append(this.thumb.render().el);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -50,8 +50,9 @@ var Whisper = Whisper || {};
|
||||||
this.clearForm();
|
this.clearForm();
|
||||||
var files = this.$input.prop('files');
|
var files = this.$input.prop('files');
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
var type = files[i].type.split('/')[0];
|
||||||
var limitKb = 1000000;
|
var limitKb = 1000000;
|
||||||
switch (files[i].type.split('/')[0]) {
|
switch (type) {
|
||||||
case 'image': limitKb = 420; break;
|
case 'image': limitKb = 420; break;
|
||||||
case 'audio': limitKb = 32000; break;
|
case 'audio': limitKb = 32000; break;
|
||||||
case 'video': limitKb = 8000; break;
|
case 'video': limitKb = 8000; break;
|
||||||
|
@ -63,9 +64,17 @@ var Whisper = Whisper || {};
|
||||||
this.deleteFiles();
|
this.deleteFiles();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
switch (type) {
|
||||||
|
case 'audio': this.addThumb('/images/audio.png'); break;
|
||||||
|
case 'video': this.addThumb('/images/video.png'); break;
|
||||||
|
case 'image':
|
||||||
var FR = new FileReader();
|
var FR = new FileReader();
|
||||||
FR.onload = this.addThumb.bind(this);
|
FR.onload = function(e) {
|
||||||
|
this.addThumb(e.target.result);
|
||||||
|
}.bind(this);
|
||||||
FR.readAsDataURL(files[i]);
|
FR.readAsDataURL(files[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -279,3 +279,13 @@
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.attachment-preview {
|
||||||
|
background: white;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -492,3 +492,10 @@ input.new-message {
|
||||||
box-shadow: 0 0 5px 0 black;
|
box-shadow: 0 0 5px 0 black;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
font-size: small; }
|
font-size: small; }
|
||||||
|
|
||||||
|
.attachment-preview {
|
||||||
|
background: white;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%; }
|
||||||
|
.attachment-preview img {
|
||||||
|
width: 100%; }
|
||||||
|
|
Loading…
Reference in a new issue