From 258a872ce301f1fb30e7ecc707a2182fbb144779 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 3 Mar 2015 13:23:55 -0800 Subject: [PATCH] Trigger update events after attachments load Mostly so we can ensure we're scrolled to the bottom when the conversation is loaded. --- js/views/attachment_view.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/js/views/attachment_view.js b/js/views/attachment_view.js index 16127d0e..6bca0ee0 100644 --- a/js/views/attachment_view.js +++ b/js/views/attachment_view.js @@ -18,6 +18,12 @@ var ImageView = Backbone.View.extend({ tagName: 'img', + events: { + 'load': 'update' + }, + update: function() { + this.$el.trigger('update'); + }, render: function(dataUrl) { this.$el.attr('src', dataUrl); return this; @@ -27,6 +33,15 @@ var MediaView = Backbone.View.extend({ initialize: function() { this.$el.attr('controls', ''); + this.$el.on('loadeddata', function() { + this.$el.trigger('update'); + }.bind(this)); + }, + events: { + 'loadeddata': 'update' + }, + update: function() { + this.$el.trigger('update'); }, render: function(dataUrl, contentType) { var $el = $(''); @@ -52,9 +67,9 @@ default: throw 'Unsupported attachment type'; } + view.$el.appendTo(this.$el); var blob = new Blob([this.model.data], {type: this.model.contentType}); view.render(window.URL.createObjectURL(blob), this.model.contentType); - view.$el.appendTo(this.$el); return this; } });