input.form doesn't work, wtf

This commit is contained in:
James Campos 2011-09-05 13:57:54 -07:00
parent 2b9262bac3
commit bc5e4d196c
2 changed files with 28 additions and 73 deletions

View File

@ -1258,8 +1258,9 @@
} }
} }
}, },
foo: function() { attach: function() {
var div, file, files; var div, file, files;
$('#autopost', QR.qr).checked = true;
files = $('#files', QR.qr); files = $('#files', QR.qr);
div = $.el('div', { div = $.el('div', {
innerHTML: "<input type=file name=upfile accept='" + QR.accept + "'><img alt='click here'><a class=x>X</a>" innerHTML: "<input type=file name=upfile accept='" + QR.accept + "'><img alt='click here'><a class=x>X</a>"
@ -1275,30 +1276,6 @@
$.add(files, div); $.add(files, div);
return file.click(); return file.click();
}, },
attach: function() {
var div, file;
$('#auto', QR.qr).checked = true;
div = $.el('div', {
innerHTML: "" + QR.file + "<a class=close>X</a>"
});
file = $('input', div);
$.bind(file, 'change', QR.change);
$.bind($('a', div), 'click', function() {
return $.rm(this.parentNode);
});
$.add($('#files', QR.qr), div);
return file.click();
},
attachNext: function() {
var file, old;
old = $('[type=file]', QR.qr);
if (file = $('#files input', QR.qr)) {
$.rm(file.parentNode);
return $.replace(old, file);
} else {
return QR.resetFile(old);
}
},
captchaNode: function(e) { captchaNode: function(e) {
QR.captcha = { QR.captcha = {
challenge: e.target.value, challenge: e.target.value,
@ -1349,7 +1326,7 @@
if (file.size > QR.MAX_FILE_SIZE) { if (file.size > QR.MAX_FILE_SIZE) {
alert('Error: File too large.'); alert('Error: File too large.');
$.rm(this.parentNode); $.rm(this.parentNode);
QR.foo(); QR.attach();
return; return;
} }
qr = QR.qr; qr = QR.qr;
@ -1400,7 +1377,7 @@
QR.qr = qr = ui.dialog('qr', { QR.qr = qr = ui.dialog('qr', {
top: '0', top: '0',
left: '0' left: '0'
}, " <a class=close>X</a> <input type=checkbox id=autohide title=autohide> <div class=move> <span class=click> <button>File</button> <span><input form=qr_form placeholder=Subject name=sub><span>Subject</span></span> <span><input form=qr_form placeholder=Name name=name><span>Name</span></span> <span><input form=qr_form placeholder=Email name=email><span>Email</span></span> <span><input form=qr_form placeholder=Password name=pwd type=password><span>Password</span></span> </span> </div> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/" + g.BOARD + "/post target=iframe id=qr_form> <div hidden> <input name=resto value=" + tid + "> <input name=mode value=regist> <input name=recaptcha_challenge_field id=challenge> <input name=recaptcha_response_field id=response> </div> <textarea placeholder=Comment name=com></textarea> <div id=files></div> <div id=captcha> <div><img></div> <span id=cl>120 Captchas</span> <input id=recaptcha_response_field autocomplete=off> </div> <div> <button>Submit</button> <label>[<input type=checkbox id=autopost title=autopost> Autopost]</label> " + QR.spoiler + " </div> <a class=error>Derp</span> </form> "); }, " <a class=close>X</a> <input type=checkbox id=autohide title=autohide> <div class=move> <span class=click> <button>File</button> <span><input form=qr_form placeholder=Subject name=sub><span>Subject</span></span> <span><input form=qr_form placeholder=Name name=name><span>Name</span></span> <span><input form=qr_form placeholder=Email name=email><span>Email</span></span> <span><input form=qr_form placeholder=Password name=pwd type=password><span>Password</span></span> </span> </div> <textarea form=qr_form placeholder=Comment name=com></textarea> <div id=files></div> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/" + g.BOARD + "/post target=iframe id=qr_form> <div hidden> <input name=resto value=" + tid + "> <input name=mode value=regist> <input name=recaptcha_challenge_field id=challenge> <input name=recaptcha_response_field id=response> </div> <div id=captcha> <div><img></div> <span id=cl>120 Captchas</span> <input id=recaptcha_response_field autocomplete=off> </div> <div> <button>Submit</button> <label>[<input type=checkbox id=autopost title=autopost> Autopost]</label> " + QR.spoiler + " </div> <a class=error>Derp</span> </form> ");
c = d.cookie; c = d.cookie;
$('[name=name]', qr).value = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; $('[name=name]', qr).value = (m = c.match(/4chan_name=([^;]+)/)) ? decodeURIComponent(m[1]) : '';
$('[name=email]', qr).value = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : ''; $('[name=email]', qr).value = (m = c.match(/4chan_email=([^;]+)/)) ? decodeURIComponent(m[1]) : '';
@ -1409,7 +1386,7 @@
if (conf['Cooldown']) { if (conf['Cooldown']) {
QR.cooldown(); QR.cooldown();
} }
$.bind($('button', qr), 'click', QR.foo); $.bind($('button', qr), 'click', QR.attach);
$.bind($('.close', qr), 'click', QR.close); $.bind($('.close', qr), 'click', QR.close);
$.bind($('.click', qr), 'mousedown', function(e) { $.bind($('.click', qr), 'mousedown', function(e) {
return e.stopPropagation(); return e.stopPropagation();
@ -1462,22 +1439,25 @@
return ta.focus(); return ta.focus();
}, },
receive: function(e) { receive: function(e) {
var data, tc, _ref; var data, qr, row, tc, _ref, _ref2;
$('iframe[name=iframe]').src = 'about:blank'; $('iframe[name=iframe]').src = 'about:blank';
qr = QR.qr;
row = (_ref = $('#files input[form]', qr)) != null ? _ref.parentNode : void 0;
data = e.data; data = e.data;
if (data) { if (data) {
data = JSON.parse(data); data = JSON.parse(data);
$.extend($('a.error', QR.qr), data); $.extend($('a.error', QR.qr), data);
tc = data.textContent; tc = data.textContent;
if (tc === 'Error: Duplicate file entry detected.') { if (tc === 'Error: Duplicate file entry detected.') {
QR.attachNext(); $.rm(row);
setTimeout(QR.submit, 1000); setTimeout(QR.submit, 1000);
} else if (tc === 'You seem to have mistyped the verification.') { } else if (tc === 'You seem to have mistyped the verification.') {
setTimeout(QR.submit, 1000); setTimeout(QR.submit, 1000);
} }
return; return;
} }
if (conf['Persistent QR'] || ((_ref = $('#files input', QR.qr)) != null ? _ref.files.length : void 0)) { $.rm(row);
if (conf['Persistent QR'] || ((_ref2 = $('#files input', QR.qr)) != null ? _ref2.files.length : void 0)) {
QR.reset(); QR.reset();
} else { } else {
QR.close(); QR.close();
@ -1495,20 +1475,10 @@
_ref.checked = false; _ref.checked = false;
} }
} }
$('textarea', QR.qr).value = ''; return $('textarea', QR.qr).value = '';
return QR.attachNext();
},
resetFile: function(old) {
var div, file;
div = $.el('div', {
innerHTML: QR.file
});
file = div.firstChild;
$.bind(file, 'change', QR.change);
return $.replace(old, file);
}, },
submit: function(e) { submit: function(e) {
var captcha, challenge, el, id, op, qr, response; var captcha, challenge, el, id, input, op, qr, response;
if (!($('textarea', QR.qr).value || $('[type=file]', QR.qr).files.length)) { if (!($('textarea', QR.qr).value || $('[type=file]', QR.qr).files.length)) {
if (e) { if (e) {
alert('Error: No text entered.'); alert('Error: No text entered.');
@ -1534,6 +1504,9 @@
if (conf['Auto Hide QR']) { if (conf['Auto Hide QR']) {
$('#autohide', qr).checked = true; $('#autohide', qr).checked = true;
} }
if (input = $('#files input', qr)) {
input.setAttribute('form', 'qr_form');
}
if (!e) { if (!e) {
$('#qr_form', qr).submit(); $('#qr_form', qr).submit();
} }

View File

@ -987,7 +987,8 @@ QR =
$('textarea', QR.qr).blur() $('textarea', QR.qr).blur()
if conf['Auto Hide QR'] if conf['Auto Hide QR']
$('#autohide', QR.qr).checked = true $('#autohide', QR.qr).checked = true
foo: -> attach: ->
$('#autopost', QR.qr).checked = true
files = $ '#files', QR.qr files = $ '#files', QR.qr
div = $.el 'div', div = $.el 'div',
innerHTML: "<input type=file name=upfile accept='#{QR.accept}'><img alt='click here'><a class=x>X</a>" innerHTML: "<input type=file name=upfile accept='#{QR.accept}'><img alt='click here'><a class=x>X</a>"
@ -997,22 +998,6 @@ QR =
$.bind $('.x', div), 'click', -> $.rm @parentNode $.bind $('.x', div), 'click', -> $.rm @parentNode
$.add files, div $.add files, div
file.click() file.click()
attach: ->
$('#auto', QR.qr).checked = true
div = $.el 'div',
innerHTML: "#{QR.file}<a class=close>X</a>"
file = $ 'input', div
$.bind file, 'change', QR.change
$.bind $('a', div), 'click', -> $.rm @parentNode
$.add $('#files', QR.qr), div
file.click()
attachNext: ->
old = $ '[type=file]', QR.qr
if file = $ '#files input', QR.qr
$.rm file.parentNode
$.replace old, file
else
QR.resetFile old
captchaNode: (e) -> captchaNode: (e) ->
QR.captcha = QR.captcha =
challenge: e.target.value challenge: e.target.value
@ -1049,7 +1034,7 @@ QR =
if file.size > QR.MAX_FILE_SIZE if file.size > QR.MAX_FILE_SIZE
alert 'Error: File too large.' alert 'Error: File too large.'
$.rm @parentNode $.rm @parentNode
QR.foo() QR.attach()
return return
{qr} = QR {qr} = QR
fr = new FileReader() fr = new FileReader()
@ -1089,6 +1074,8 @@ QR =
<span><input form=qr_form placeholder=Password name=pwd type=password><span>Password</span></span> <span><input form=qr_form placeholder=Password name=pwd type=password><span>Password</span></span>
</span> </span>
</div> </div>
<textarea form=qr_form placeholder=Comment name=com></textarea>
<div id=files></div>
<form enctype=multipart/form-data method=post action=http://sys.4chan.org/#{g.BOARD}/post target=iframe id=qr_form> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/#{g.BOARD}/post target=iframe id=qr_form>
<div hidden> <div hidden>
<input name=resto value=#{tid}> <input name=resto value=#{tid}>
@ -1096,8 +1083,6 @@ QR =
<input name=recaptcha_challenge_field id=challenge> <input name=recaptcha_challenge_field id=challenge>
<input name=recaptcha_response_field id=response> <input name=recaptcha_response_field id=response>
</div> </div>
<textarea placeholder=Comment name=com></textarea>
<div id=files></div>
<div id=captcha> <div id=captcha>
<div><img></div> <div><img></div>
<span id=cl>120 Captchas</span> <span id=cl>120 Captchas</span>
@ -1119,8 +1104,7 @@ QR =
$('[name=pwd]', qr).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value $('[name=pwd]', qr).value = if m = c.match(/4chan_pass=([^;]+)/) then decodeURIComponent m[1] else $('input[name=pwd]').value
$('textarea', qr).value = text $('textarea', qr).value = text
QR.cooldown() if conf['Cooldown'] QR.cooldown() if conf['Cooldown']
$.bind $('button', qr), 'click', QR.foo $.bind $('button', qr), 'click', QR.attach
#$.bind $('[type=file]', qr), 'change', QR.change
$.bind $('.close', qr), 'click', QR.close $.bind $('.close', qr), 'click', QR.close
$.bind $('.click', qr), 'mousedown', (e) -> e.stopPropagation() $.bind $('.click', qr), 'mousedown', (e) -> e.stopPropagation()
$.bind $('form', qr), 'submit', QR.submit $.bind $('form', qr), 'submit', QR.submit
@ -1161,17 +1145,20 @@ QR =
ta.focus() ta.focus()
receive: (e) -> receive: (e) ->
$('iframe[name=iframe]').src = 'about:blank' $('iframe[name=iframe]').src = 'about:blank'
{qr} = QR
row = $('#files input[form]', qr)?.parentNode
{data} = e {data} = e
if data if data
data = JSON.parse data data = JSON.parse data
$.extend $('a.error', QR.qr), data $.extend $('a.error', QR.qr), data
tc = data.textContent tc = data.textContent
if tc is 'Error: Duplicate file entry detected.' if tc is 'Error: Duplicate file entry detected.'
QR.attachNext() $.rm row
setTimeout QR.submit, 1000 setTimeout QR.submit, 1000
else if tc is 'You seem to have mistyped the verification.' else if tc is 'You seem to have mistyped the verification.'
setTimeout QR.submit, 1000 setTimeout QR.submit, 1000
return return
$.rm row
if conf['Persistent QR'] or $('#files input', QR.qr)?.files.length if conf['Persistent QR'] or $('#files input', QR.qr)?.files.length
QR.reset() QR.reset()
else else
@ -1183,13 +1170,6 @@ QR =
reset: -> reset: ->
$('[name=spoiler]', QR.qr)?.checked = false unless conf['Remember Spoiler'] $('[name=spoiler]', QR.qr)?.checked = false unless conf['Remember Spoiler']
$('textarea', QR.qr).value = '' $('textarea', QR.qr).value = ''
QR.attachNext()
resetFile: (old) ->
div = $.el 'div'
innerHTML: QR.file
file = div.firstChild
$.bind file, 'change', QR.change
$.replace old, file
submit: (e) -> submit: (e) ->
#XXX e is undefined if method is called explicitly, eg, from auto posting #XXX e is undefined if method is called explicitly, eg, from auto posting
unless $('textarea', QR.qr).value or $('[type=file]', QR.qr).files.length unless $('textarea', QR.qr).value or $('[type=file]', QR.qr).files.length
@ -1209,6 +1189,8 @@ QR =
$('#challenge', qr).value = challenge $('#challenge', qr).value = challenge
$('#response', qr).value = response $('#response', qr).value = response
$('#autohide', qr).checked = true if conf['Auto Hide QR'] $('#autohide', qr).checked = true if conf['Auto Hide QR']
if input = $ '#files input', qr
input.setAttribute 'form', 'qr_form'
$('#qr_form', qr).submit() if not e $('#qr_form', qr).submit() if not e
QR.sage = /sage/i.test $('[name=email]', qr).value QR.sage = /sage/i.test $('[name=email]', qr).value
if conf['Thread Watcher'] and conf['Auto Watch Reply'] if conf['Thread Watcher'] and conf['Auto Watch Reply']