diff --git a/4chan_x.user.js b/4chan_x.user.js
index ceb127c8f..487308238 100644
--- a/4chan_x.user.js
+++ b/4chan_x.user.js
@@ -1331,11 +1331,23 @@
return $('#cl', QR.qr).textContent = captchas.length + ' captchas';
},
change: function(e) {
- if (this.files[0].size > QR.MAX_FILE_SIZE) {
+ var file, fr;
+ file = this.files[0];
+ if (file.size > QR.MAX_FILE_SIZE) {
alert('Error: File too large.');
QR.resetFile(this);
return $('[type=file]', QR.qr).click();
} else {
+ fr = new FileReader();
+ fr.onload = function(e) {
+ var img;
+ img = $.el('img', {
+ src: e.target.result
+ });
+ return $.append($('#thumbs', QR.qr), img);
+ };
+ fr.readAsDataURL(file);
+ return;
if (this === $('#files div:last-of-type input', QR.qr)) {
return QR.attach();
}
@@ -1400,13 +1412,12 @@
"
#XXX use dom methods to set values instead of injecting raw user input into your html -_-;
$('[name=pwd]', qr).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value
- $.bind $('[type=file]', qr), 'change', QR.change
$.bind $('#attach', qr), 'click', QR.attach
*/
QR.qr = qr = ui.dialog('qr', {
top: '0',
left: '0'
- }, " X
Subject Name Email
");
+ }, " X Subject Name Email
");
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]) : '';
@@ -1417,6 +1428,7 @@
$.bind($('button', qr), 'click', function() {
return $('[type=file]', qr).click();
});
+ $.bind($('[type=file]', qr), 'change', QR.change);
$.bind($('.close', qr), 'click', QR.close);
$.bind($('.click', qr), 'mousedown', function(e) {
return e.stopPropagation();
diff --git a/script.coffee b/script.coffee
index b6e68777e..b7f3adc0f 100644
--- a/script.coffee
+++ b/script.coffee
@@ -1040,11 +1040,19 @@ QR =
captchas or= $.get 'captchas', []
$('#cl', QR.qr).textContent = captchas.length + ' captchas'
change: (e) ->
- if @files[0].size > QR.MAX_FILE_SIZE
+ file = @files[0]
+ if file.size > QR.MAX_FILE_SIZE
alert 'Error: File too large.'
QR.resetFile @
$('[type=file]', QR.qr).click()
else
+ fr = new FileReader()
+ fr.onload = (e) ->
+ img = $.el 'img',
+ src: e.target.result
+ $.append $('#thumbs', QR.qr), img
+ fr.readAsDataURL file
+ return
if @ is $('#files div:last-of-type input', QR.qr)
QR.attach()
close: ->
@@ -1089,7 +1097,6 @@ QR =
"
#XXX use dom methods to set values instead of injecting raw user input into your html -_-;
$('[name=pwd]', qr).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value
- $.bind $('[type=file]', qr), 'change', QR.change
$.bind $('#attach', qr), 'click', QR.attach
###
QR.qr = qr = ui.dialog 'qr', top: '0', left: '0', "
@@ -1108,13 +1115,14 @@ QR =
+
120 Captchas
-
+
@@ -1128,6 +1136,7 @@ QR =
$('textarea', qr).value = text
QR.cooldown() if conf['Cooldown']
$.bind $('button', qr), 'click', -> $('[type=file]', qr).click()
+ $.bind $('[type=file]', qr), 'change', QR.change
$.bind $('.close', qr), 'click', QR.close
$.bind $('.click', qr), 'mousedown', (e) -> e.stopPropagation()
$.bind $('form', qr), 'submit', QR.submit