From 53a9ab4834aa80ffebd2358bcfcb16176fbf13c7 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 25 May 2015 10:43:35 -0700 Subject: [PATCH] Fix bugs with handling large image attachments * Avoid infinite loop scaling too-big images * Don't crash if no file is selected * Fix file size toast Fixes #242 // FREEBIE --- js/views/file_input_view.js | 10 +++++++--- js/views/toast_view.js | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/js/views/file_input_view.js b/js/views/file_input_view.js index 9660e2cfc..43f5bb5c9 100644 --- a/js/views/file_input_view.js +++ b/js/views/file_input_view.js @@ -42,6 +42,9 @@ // hack if (this.window && this.window.chrome && this.window.chrome.fileSystem) { this.window.chrome.fileSystem.chooseEntry({type: 'openFile'}, function(entry) { + if (!entry) { + return; + } entry.file(function(file) { this.file = file; this.previewImages(); @@ -97,7 +100,6 @@ quality = quality * maxSize / blob.size; if (quality < 50) { quality = 50; - i = 1; } } while (i > 0 && blob.size > maxSize); @@ -130,9 +132,11 @@ case 'video': limitKb = 8000; break; } if ((blob.size/1024).toFixed(4) >= limitKb) { - new Whisper.FileSizeToast({ + var toast = new Whisper.FileSizeToast({ model: {limit: limitKb} - }).render(); + }); + toast.$el.insertAfter(this.$el); + toast.render(); this.deleteFiles(); } }.bind(this)); diff --git a/js/views/toast_view.js b/js/views/toast_view.js index 8d967d69f..cb4c39e97 100644 --- a/js/views/toast_view.js +++ b/js/views/toast_view.js @@ -29,7 +29,7 @@ render: function() { this.$el.html(Mustache.render(this.template, this.model)); - this.$el.appendTo($('body')).show(); + this.$el.show(); setTimeout(this.close.bind(this), 2000); } });