diff --git a/4chan_x.user.js b/4chan_x.user.js index d0f808f53..bf3807615 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1254,6 +1254,7 @@ QR.accept = "'" + accept + "'"; QR.MAX_FILE_SIZE = $('input[name=MAX_FILE_SIZE]').value; QR.spoiler = $('.postarea label') ? ' ' : ''; + QR.file = ""; if (conf['Persistent QR']) { QR.dialog(); if (conf['Auto Hide QR']) { @@ -1270,7 +1271,7 @@ var div, file; $('#auto', QR.qr).checked = true; div = $.el('div', { - innerHTML: "X" + innerHTML: "" + QR.file + "X" }); file = $('input', div); $.bind(file, 'change', QR.change); @@ -1281,18 +1282,14 @@ return file.click(); }, attachNext: function() { - var file, oldFile; - oldFile = $('[type=file]', QR.qr); + var file, old; + old = $('[type=file]', QR.qr); if (file = $('#files input', QR.qr)) { $.rm(file.parentNode); + return $.replace(old, file); } else { - file = $.el('input', { - type: 'file', - name: 'upfile', - accept: QR.accept - }); + return $.refreshFile(old); } - return $.replace(oldFile, file); }, captchaNode: function(e) { var c; @@ -1329,14 +1326,25 @@ $('#cl', QR.qr).textContent = captchas.length + ' captchas'; return captcha; }, - change: function() { - if (this.files[0].size > QR.MAX_FILE_SIZE) { - alert('Error: File too large.'); - return this.click(); - } else { - $.unbind(this, 'change', QR.change); - return QR.attach(); + change: function(e) { + if (!(this.files[0].size > QR.MAX_FILE_SIZE)) { + return; } + alert('Error: File too large.'); + return QR.refreshFile(this); + }, + refreshFile: function(old) { + var div, file; + div = $.el('div', { + innerHTML: QR.file + }); + file = div.firstChild; + $.bind(file, 'change', QR.change); + return $.replace(old, file); + }, + change1: function() { + $.unbind(this, 'change', QR.change); + return QR.attach(); }, close: function() { $.rm(QR.qr); @@ -1375,7 +1383,7 @@ QR.qr = qr = ui.dialog('qr', { top: '0', left: '0' - }, " X
Quick Reply
" + QR.spoiler + "
" + ($.get('captchas', []).length) + " captchas
attach another file
"); + }, " X
Quick Reply
" + QR.spoiler + "
" + ($.get('captchas', []).length) + " captchas
" + QR.file + "
attach another file
"); c = d.cookie; $('[name=name]', qr).value = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; $('[name=email]', qr).value = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; diff --git a/script.coffee b/script.coffee index 753fc1754..fc2b5b5bb 100644 --- a/script.coffee +++ b/script.coffee @@ -987,6 +987,7 @@ QR = QR.accept = "'#{accept}'" QR.MAX_FILE_SIZE = $('input[name=MAX_FILE_SIZE]').value QR.spoiler = if $('.postarea label') then ' ' else '' + QR.file = "" if conf['Persistent QR'] QR.dialog() if conf['Auto Hide QR'] @@ -998,22 +999,19 @@ QR = attach: -> $('#auto', QR.qr).checked = true div = $.el 'div', - innerHTML: "X" + innerHTML: "#{QR.file}X" file = $ 'input', div $.bind file, 'change', QR.change $.bind $('a', div), 'click', -> $.rm @parentNode $.append $('#files', QR.qr), div file.click() attachNext: -> - oldFile = $ '[type=file]', QR.qr + old = $ '[type=file]', QR.qr if file = $ '#files input', QR.qr $.rm file.parentNode + $.replace old, file else - file = $.el 'input', - type: 'file' - name: 'upfile' - accept: QR.accept - $.replace oldFile, file + $.refreshFile old captchaNode: (e) -> c = e.target.value $('img', QR.qr).src = "http://www.google.com/recaptcha/api/image?c=#{c}" if QR.qr @@ -1038,13 +1036,19 @@ QR = $.set 'captchas', captchas $('#cl', QR.qr).textContent = captchas.length + ' captchas' captcha - change: -> - if @files[0].size > QR.MAX_FILE_SIZE - alert 'Error: File too large.' - @.click() - else - $.unbind @, 'change', QR.change - QR.attach() + change: (e) -> + return unless @files[0].size > QR.MAX_FILE_SIZE + alert 'Error: File too large.' + QR.refreshFile @ + refreshFile: (old) -> + div = $.el 'div' + innerHTML: QR.file + file = div.firstChild + $.bind file, 'change', QR.change + $.replace old, file + change1: -> + $.unbind @, 'change', QR.change + QR.attach() close: -> $.rm QR.qr QR.qr = null @@ -1078,7 +1082,7 @@ QR =
#{$.get('captchas', []).length} captchas
-
+
#{QR.file}
attach another file