From c35f959f4263f24c81872a954ea83013c6110135 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 2 Sep 2011 22:20:23 -0700 Subject: [PATCH] reset file --- 4chan_x.user.js | 17 ++++++++++++----- script.coffee | 11 ++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 5972d827b..77dba3b61 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1388,13 +1388,13 @@ return ta.focus(); }, receive: function(e) { - var data; + var data, file; data = e.data; if (data) { return $.extend($('a.error', QR.el), JSON.parse(data)); } else { - if (conf['Persistent QR']) { - QR.reset(); + if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) { + QR.reset(file); } else { QR.close(); } @@ -1405,8 +1405,15 @@ } } }, - reset: function() { - return $('textarea', QR.el).value = ''; + reset: function(file) { + var oldFile; + $('textarea', QR.el).value = ''; + oldFile = $('[type=file]', QR.el); + file || (file = $.el('input', { + type: 'file', + name: 'upfile' + })); + return $.replace(oldFile, file); }, submit: function(e) { var captcha, challenge, el, response; diff --git a/script.coffee b/script.coffee index ffc5d609f..368556617 100644 --- a/script.coffee +++ b/script.coffee @@ -1091,16 +1091,21 @@ QR = if data $.extend $('a.error', QR.el), JSON.parse data else - if conf['Persistent QR'] - QR.reset() + if ((file = $('#files input', QR.el)) and file.files.length) or conf['Persistent QR'] + QR.reset file else QR.close() if conf['Cooldown'] cooldown = Date.now() + 30*SECOND $.set "cooldown/#{g.BOARD}", cooldown QR.cooldown() - reset: -> + reset: (file) -> $('textarea', QR.el).value = '' + oldFile = $ '[type=file]', QR.el + file or= $.el 'input', + type: 'file' + name: 'upfile' + $.replace oldFile, file submit: (e) -> #XXX e is undefined if we're called from QR.autoPost $('.error', qr.el).textContent = ''