From bdfcf60d8bc90366d51298c1155c40c3c72c344e Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 27 Feb 2013 16:04:29 +0100 Subject: [PATCH] Fix last file input bugs. #932 --- 4chan_x.user.js | 17 ++++++++++++----- lib/$.coffee | 7 +++++-- src/qr.coffee | 7 ++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 0d5b9ee92..240f75585 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -661,9 +661,12 @@ fd = new FormData(); for (key in form) { val = form[key]; - if (val instanceof Blob) { + if (!val) { + continue; + } + if (val.size && val.name) { fd.append(key, val, val.name); - } else if (val) { + } else { fd.append(key, val); } } @@ -6008,7 +6011,7 @@ }, fileInput: function(files) { var file, length, max, post, _i, _len, _ref, _ref1; - if (files instanceof Event) { + if (this instanceof Element) { files = __slice.call(this.files); QR.nodes.fileInput.value = null; } @@ -6042,9 +6045,10 @@ QR.error("" + file.name + ": File too large (file: " + ($.bytesToString(file.size)) + ", max: " + ($.bytesToString(max)) + ")."); } else if (_ref1 = file.type, __indexOf.call(QR.mimeTypes, _ref1) < 0) { QR.error("" + file.name + ": Unsupported file type."); - } else if ((post = QR.posts[QR.posts.length - 1]).file) { - post = new QR.post(); } else { + if ((post = QR.posts[QR.posts.length - 1]).file) { + post = new QR.post(); + } post.setFile(file); } } @@ -6459,6 +6463,9 @@ }, load: function() { var challenge; + if (!this.nodes.challenge.firstChild) { + return; + } this.timeout = Date.now() + $.unsafeWindow.RecaptchaState.timeout * $.SECOND - $.MINUTE; challenge = this.nodes.challenge.firstChild.value; this.nodes.img.alt = challenge; diff --git a/lib/$.coffee b/lib/$.coffee index 45754181a..6f84e0feb 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -39,9 +39,12 @@ $.extend $, return new FormData form fd = new FormData() for key, val of form - if val instanceof Blob + continue unless val + # XXX GM bug + # if val instanceof Blob + if val.size and val.name fd.append key, val, val.name - else if val + else fd.append key, val fd ajax: (url, callbacks, opts={}) -> diff --git a/src/qr.coffee b/src/qr.coffee index 709093f0d..def52a63b 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -310,7 +310,7 @@ QR = QR.open() QR.fileInput files fileInput: (files) -> - if files instanceof Event # file input + if @ instanceof Element #or files instanceof Event # file input files = [@files...] QR.nodes.fileInput.value = null # Don't hold the files from being modified on windows {length} = files @@ -339,9 +339,9 @@ QR = QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})." else unless file.type in QR.mimeTypes QR.error "#{file.name}: Unsupported file type." - else if (post = QR.posts[QR.posts.length - 1]).file - post = new QR.post() else + if (post = QR.posts[QR.posts.length - 1]).file + post = new QR.post() post.setFile file $.addClass QR.nodes.el, 'dump' resetThreadSelector: -> @@ -627,6 +627,7 @@ QR = @count() $.set 'captchas', @captchas load: -> + return unless @nodes.challenge.firstChild # -1 minute to give upload some time. @timeout = Date.now() + $.unsafeWindow.RecaptchaState.timeout * $.SECOND - $.MINUTE challenge = @nodes.challenge.firstChild.value