From 4fb824c30434bd09377401ddee619eb23776dd30 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 14 Feb 2013 22:23:33 +0100 Subject: [PATCH] Indicate filesize and max filesize in case of too large selected files. --- 4chan_x.user.js | 14 +++++++------- src/qr.coffee | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index d3c0d9bde..a705c9cdd 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4395,7 +4395,7 @@ if (this.files.length === 1) { file = this.files[0]; if (file.size > this.max) { - QR.error('File too large.'); + QR.error("File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(this.max)) + ")."); QR.resetFileInput(); } else if (-1 === QR.mimeTypes.indexOf(file.type)) { QR.error('Unsupported file type.'); @@ -4409,7 +4409,7 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { file = _ref[_i]; if (file.size > this.max) { - QR.error("File " + file.name + " is too large (" + ($.bytesToString(file.size)) + ")."); + QR.error("File " + file.name + " is too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(this.max)) + ")."); } else if (-1 === QR.mimeTypes.indexOf(file.type)) { QR.error("" + file.name + ": Unsupported file type."); } @@ -4472,7 +4472,7 @@ } _Class.prototype.setFile = function(file) { - var fileUrl, img, + var fileURL, img, _this = this; this.file = file; this.el.title = "" + file.name + " (" + ($.bytesToString(file.size)) + ")"; @@ -4487,13 +4487,13 @@ return; } URL.revokeObjectURL(this.url); - fileUrl = url.createObjectURL(file); + fileURL = URL.createObjectURL(file); img = $.el('img'); $.on(img, 'load', function() { var c, data, i, l, s, ui8a, _i; s = 90 * 3; if (img.height < s || img.width < s) { - _this.url = fileUrl; + _this.url = fileURL; _this.el.style.backgroundImage = "url(" + _this.url + ")"; return; } @@ -4518,9 +4518,9 @@ type: 'image/png' })); _this.el.style.backgroundImage = "url(" + _this.url + ")"; - return URL.revokeObjectURL(fileUrl); + return URL.revokeObjectURL(fileURL); }); - return img.src = fileUrl; + return img.src = fileURL; }; _Class.prototype.rmFile = function() { diff --git a/src/qr.coffee b/src/qr.coffee index d2a2fa110..d01512356 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -290,7 +290,7 @@ QR = if @files.length is 1 file = @files[0] if file.size > @max - QR.error 'File too large.' + QR.error "File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString @max})." QR.resetFileInput() else if -1 is QR.mimeTypes.indexOf file.type QR.error 'Unsupported file type.' @@ -301,7 +301,7 @@ QR = # Create new replies with these files. for file in @files if file.size > @max - QR.error "File #{file.name} is too large (#{$.bytesToString file.size})." + QR.error "File #{file.name} is too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString @max})." else if -1 is QR.mimeTypes.indexOf file.type QR.error "#{file.name}: Unsupported file type." unless QR.replies[QR.replies.length - 1].file @@ -361,7 +361,7 @@ QR = URL.revokeObjectURL @url # Create a redimensioned thumbnail. - fileUrl = url.createObjectURL file + fileURL = URL.createObjectURL file img = $.el 'img' $.on img, 'load', => @@ -371,7 +371,7 @@ QR = # to avoid crappy resized quality. s = 90*3 if img.height < s or img.width < s - @url = fileUrl + @url = fileURL @el.style.backgroundImage = "url(#{@url})" return if img.height <= img.width @@ -395,9 +395,9 @@ QR = @url = URL.createObjectURL new Blob [ui8a], type: 'image/png' @el.style.backgroundImage = "url(#{@url})" - URL.revokeObjectURL fileUrl + URL.revokeObjectURL fileURL - img.src = fileUrl + img.src = fileURL rmFile: -> QR.resetFileInput() delete @file