2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-11 11:27:22 +00:00
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2015-12-22 01:36:33 +00:00
|
|
|
var FileView = Backbone.View.extend({
|
|
|
|
tagName: 'a',
|
|
|
|
initialize: function(dataUrl) {
|
|
|
|
this.dataUrl = dataUrl;
|
2015-12-26 05:12:17 +00:00
|
|
|
this.$el.text(i18n('unsupportedAttachment'));
|
2015-12-22 01:36:33 +00:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click': 'open'
|
|
|
|
},
|
|
|
|
open: function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
window.open(this.dataUrl, '_blank');
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
this.$el.attr('href', this.dataUrl);
|
|
|
|
this.trigger('update');
|
|
|
|
return this;
|
|
|
|
}
|
2015-12-05 06:39:15 +00:00
|
|
|
});
|
|
|
|
|
2015-03-02 19:49:23 +00:00
|
|
|
var ImageView = Backbone.View.extend({
|
|
|
|
tagName: 'img',
|
2015-10-21 17:52:20 +00:00
|
|
|
initialize: function(dataUrl) {
|
|
|
|
this.dataUrl = dataUrl;
|
|
|
|
},
|
2015-03-03 21:23:55 +00:00
|
|
|
events: {
|
2015-10-20 21:18:46 +00:00
|
|
|
'load': 'update',
|
|
|
|
'click': 'open'
|
2015-03-03 21:23:55 +00:00
|
|
|
},
|
|
|
|
update: function() {
|
2015-11-12 18:35:29 +00:00
|
|
|
this.trigger('update');
|
2015-03-03 21:23:55 +00:00
|
|
|
},
|
2015-10-20 21:18:46 +00:00
|
|
|
open: function () {
|
2015-10-21 17:52:20 +00:00
|
|
|
window.open(this.dataUrl, '_blank');
|
2015-10-20 21:18:46 +00:00
|
|
|
},
|
2015-10-21 17:52:20 +00:00
|
|
|
render: function() {
|
2015-12-05 06:39:15 +00:00
|
|
|
this.$el.attr('src', this.dataUrl);
|
|
|
|
return this;
|
2015-03-02 19:49:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-03 21:05:39 +00:00
|
|
|
var MediaView = Backbone.View.extend({
|
2015-10-21 17:52:20 +00:00
|
|
|
initialize: function(dataUrl, contentType) {
|
|
|
|
this.dataUrl = dataUrl;
|
|
|
|
this.contentType = contentType;
|
2015-03-02 19:49:23 +00:00
|
|
|
this.$el.attr('controls', '');
|
2015-03-03 21:23:55 +00:00
|
|
|
},
|
|
|
|
events: {
|
2015-11-12 18:35:29 +00:00
|
|
|
'canplay': 'canplay'
|
2015-03-03 21:23:55 +00:00
|
|
|
},
|
2015-11-12 18:35:29 +00:00
|
|
|
canplay: function() {
|
|
|
|
this.trigger('update');
|
2015-03-02 19:49:23 +00:00
|
|
|
},
|
2015-10-21 17:52:20 +00:00
|
|
|
render: function() {
|
2015-03-02 19:49:23 +00:00
|
|
|
var $el = $('<source>');
|
2015-10-21 17:52:20 +00:00
|
|
|
$el.attr('src', this.dataUrl);
|
|
|
|
$el.attr('type', this.contentType);
|
2015-03-02 19:49:23 +00:00
|
|
|
this.$el.append($el);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-03 21:05:39 +00:00
|
|
|
var AudioView = MediaView.extend({ tagName: 'audio' });
|
|
|
|
var VideoView = MediaView.extend({ tagName: 'video' });
|
|
|
|
|
2015-01-11 11:27:22 +00:00
|
|
|
Whisper.AttachmentView = Backbone.View.extend({
|
2015-03-03 02:37:20 +00:00
|
|
|
tagName: 'span',
|
2015-03-02 19:49:23 +00:00
|
|
|
className: 'attachment',
|
2015-01-11 11:27:22 +00:00
|
|
|
render: function() {
|
2015-10-21 17:52:20 +00:00
|
|
|
var View;
|
2015-03-02 19:49:23 +00:00
|
|
|
switch(this.model.contentType.split('/')[0]) {
|
2015-10-21 17:52:20 +00:00
|
|
|
case 'image': View = ImageView; break;
|
|
|
|
case 'audio': View = AudioView; break;
|
|
|
|
case 'video': View = VideoView; break;
|
2015-12-22 01:36:33 +00:00
|
|
|
default : View = FileView; break;
|
2015-03-02 19:49:23 +00:00
|
|
|
}
|
2015-12-22 01:36:33 +00:00
|
|
|
var blob = new Blob([this.model.data], {type: this.model.contentType});
|
|
|
|
var view = new View(window.URL.createObjectURL(blob), this.model.contentType);
|
|
|
|
view.$el.appendTo(this.$el);
|
|
|
|
view.on('update', this.trigger.bind(this, 'update'));
|
|
|
|
view.render();
|
|
|
|
return this;
|
2015-01-11 11:27:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|