diff --git a/index.html b/index.html index 61a299a9..46c6306b 100644 --- a/index.html +++ b/index.html @@ -156,10 +156,8 @@ + diff --git a/js/views/attachment_preview_view.js b/js/views/attachment_preview_view.js new file mode 100644 index 00000000..421335ed --- /dev/null +++ b/js/views/attachment_preview_view.js @@ -0,0 +1,31 @@ +/* vim: ts=4:sw=4:expandtab + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +var Whisper = Whisper || {}; + +(function () { + 'use strict'; + Whisper.AttachmentPreviewView = Backbone.View.extend({ + className: 'imageAttachment', + initialize: function() { + this.template = $('#attachment-preview').html(); + Mustache.parse(this.template); + }, + render: function() { + this.$el.html(Mustache.render(this.template, {source: this.src})); + return this; + } + }); +})(); diff --git a/js/views/file_input_view.js b/js/views/file_input_view.js index 742ef07b..634b17f5 100644 --- a/js/views/file_input_view.js +++ b/js/views/file_input_view.js @@ -23,6 +23,7 @@ var Whisper = Whisper || {}; initialize: function() { this.$input = this.$el.find('input[type=file]'); this.modal = new Whisper.ModalView({el: $('#file-modal')}); + this.thumb = new Whisper.AttachmentPreviewView(); }, events: { @@ -31,9 +32,8 @@ var Whisper = Whisper || {}; }, addThumb: function(e) { - var attachmentPreview = $('#attachment-preview').html(); - Mustache.parse(attachmentPreview); - this.$el.append($(Mustache.render(attachmentPreview, {source: e.target.result}))); + this.thumb.src = e.target.result; + this.$el.append(this.thumb.render().el); }, previewImages: function() { @@ -76,7 +76,7 @@ var Whisper = Whisper || {}; }, clearForm: function() { - this.$el.find('div.imageAttachment').remove(); + this.thumb.remove(); }, deleteFiles: function() {