captcha caching
This commit is contained in:
parent
e440799893
commit
1da577fead
@ -1234,11 +1234,15 @@
|
|||||||
QR.challengeNode({
|
QR.challengeNode({
|
||||||
target: holder.firstChild
|
target: holder.firstChild
|
||||||
});
|
});
|
||||||
return $.bind(window, 'message', QR.receive);
|
$.bind(window, 'message', QR.receive);
|
||||||
|
return $('#recaptcha_response_field').id = '';
|
||||||
},
|
},
|
||||||
challengeNode: function(e) {
|
challengeNode: function(e) {
|
||||||
|
var c;
|
||||||
|
c = e.target.value;
|
||||||
|
$('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=" + c;
|
||||||
return QR.captcha = {
|
return QR.captcha = {
|
||||||
challenge: e.target.value,
|
challenge: c,
|
||||||
time: Date.now()
|
time: Date.now()
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -1259,14 +1263,33 @@
|
|||||||
qr.el = ui.dialog('qr', {
|
qr.el = ui.dialog('qr', {
|
||||||
top: '0',
|
top: '0',
|
||||||
left: '0'
|
left: '0'
|
||||||
}, " <a class=close title=close>X</a><input type=checkbox id=autohide title=autohide> <div class=move><input placeholder=Name name=name form=qr_form>Quick Reply</div> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/" + g.BOARD + "/post target=iframe id=qr_form> <input type=hidden name=resto value=" + g.THREAD_ID + "> <input type=hidden name=mode value=regist> <input type=hidden name=recaptcha_challenge_field id=challenge> <input type=hidden name=recaptcha_response_field id=response> <div><input placeholder=Email name=email></div> <div><input placeholder=Subject name=sub><button>Submit</button></div> <div><textarea placeholder=Comment name=com>" + text + "</textarea></div> <div><img src=http://www.google.com/recaptcha/api/image?c=" + QR.captcha.challenge + "></div> <div><input placeholder=Verification autocomplete=off id=recaptcha_response_field ></div> <div><input name=upfile type=file></div> <div><input placeholder=Password name=pwd type=password></div> </form> <a class=error></a> ");
|
}, " <a class=close title=close>X</a><input type=checkbox id=autohide title=autohide> <div class=move><input placeholder=Name name=name form=qr_form>Quick Reply</div> <form enctype=multipart/form-data method=post action=http://sys.4chan.org/" + g.BOARD + "/post target=iframe id=qr_form> <input type=hidden name=resto value=" + g.THREAD_ID + "> <input type=hidden name=mode value=regist> <input type=hidden name=recaptcha_challenge_field id=challenge> <input type=hidden name=recaptcha_response_field id=response> <div><input placeholder=Email name=email></div> <div><input placeholder=Subject name=sub><button>Submit</button></div> <div><textarea placeholder=Comment name=com>" + text + "</textarea></div> <div><img src=http://www.google.com/recaptcha/api/image?c=" + QR.captcha.challenge + "></div> <div><input placeholder=Verification autocomplete=off id=recaptcha_response_field><span id=cl>" + ($.get('captchas', []).length) + " captchas</span></div> <div><input name=upfile type=file></div> <div><input placeholder=Password name=pwd type=password></div> </form> <a class=error></a> ");
|
||||||
$.bind($('form', qr.el), 'submit', QR.submit);
|
$.bind($('form', qr.el), 'submit', QR.submit);
|
||||||
|
$.bind($('#recaptcha_response_field', qr.el), 'keydown', QR.keydown);
|
||||||
$.append(d.body, qr.el);
|
$.append(d.body, qr.el);
|
||||||
ta = $('textarea', qr.el);
|
ta = $('textarea', qr.el);
|
||||||
l = text.length;
|
l = text.length;
|
||||||
ta.setSelectionRange(l, l);
|
ta.setSelectionRange(l, l);
|
||||||
return ta.focus();
|
return ta.focus();
|
||||||
},
|
},
|
||||||
|
keydown: function(e) {
|
||||||
|
var captcha, captchas;
|
||||||
|
if (!(e.keyCode === 13 && this.value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($('textarea', qr.el).value || $('[type=file]', qr.el).files.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
captcha = QR.captcha;
|
||||||
|
captcha.response = this.value;
|
||||||
|
captchas = $.get('captchas', []);
|
||||||
|
captchas.push(captcha);
|
||||||
|
$.set('captchas', captchas);
|
||||||
|
this.value = '';
|
||||||
|
Recaptcha.reload();
|
||||||
|
return this.nextSibling.textContent = captchas.length + ' captchas';
|
||||||
|
},
|
||||||
submit: function(e) {
|
submit: function(e) {
|
||||||
$('#challenge', qr.el).value = QR.captcha.challenge;
|
$('#challenge', qr.el).value = QR.captcha.challenge;
|
||||||
return $('#response', qr.el).value = $('#recaptcha_response_field', qr.el).value;
|
return $('#response', qr.el).value = $('#recaptcha_response_field', qr.el).value;
|
||||||
|
|||||||
@ -970,9 +970,13 @@ QR =
|
|||||||
$.bind holder, 'DOMNodeInserted', QR.challengeNode
|
$.bind holder, 'DOMNodeInserted', QR.challengeNode
|
||||||
QR.challengeNode target: holder.firstChild
|
QR.challengeNode target: holder.firstChild
|
||||||
$.bind window, 'message', QR.receive
|
$.bind window, 'message', QR.receive
|
||||||
|
# nuke id so qr's field focuses on recaptcha reload, instead of normal form's
|
||||||
|
$('#recaptcha_response_field').id = ''
|
||||||
challengeNode: (e) ->
|
challengeNode: (e) ->
|
||||||
|
c = e.target.value
|
||||||
|
$('img', qr.el).src = "http://www.google.com/recaptcha/api/image?c=#{c}"
|
||||||
QR.captcha =
|
QR.captcha =
|
||||||
challenge: e.target.value
|
challenge: c
|
||||||
time: Date.now()
|
time: Date.now()
|
||||||
node: (root) ->
|
node: (root) ->
|
||||||
quote = $ 'a.quotejs + a', root
|
quote = $ 'a.quotejs + a', root
|
||||||
@ -993,18 +997,31 @@ QR =
|
|||||||
<div><input placeholder=Subject name=sub><button>Submit</button></div>
|
<div><input placeholder=Subject name=sub><button>Submit</button></div>
|
||||||
<div><textarea placeholder=Comment name=com>#{text}</textarea></div>
|
<div><textarea placeholder=Comment name=com>#{text}</textarea></div>
|
||||||
<div><img src=http://www.google.com/recaptcha/api/image?c=#{QR.captcha.challenge}></div>
|
<div><img src=http://www.google.com/recaptcha/api/image?c=#{QR.captcha.challenge}></div>
|
||||||
<div><input placeholder=Verification autocomplete=off id=recaptcha_response_field ></div>
|
<div><input placeholder=Verification autocomplete=off id=recaptcha_response_field><span id=cl>#{$.get('captchas', []).length} captchas</span></div>
|
||||||
<div><input name=upfile type=file></div>
|
<div><input name=upfile type=file></div>
|
||||||
<div><input placeholder=Password name=pwd type=password></div>
|
<div><input placeholder=Password name=pwd type=password></div>
|
||||||
</form>
|
</form>
|
||||||
<a class=error></a>
|
<a class=error></a>
|
||||||
"
|
"
|
||||||
$.bind $('form', qr.el), 'submit', QR.submit
|
$.bind $('form', qr.el), 'submit', QR.submit
|
||||||
|
$.bind $('#recaptcha_response_field', qr.el), 'keydown', QR.keydown
|
||||||
$.append d.body, qr.el
|
$.append d.body, qr.el
|
||||||
ta = $ 'textarea', qr.el
|
ta = $ 'textarea', qr.el
|
||||||
l = text.length
|
l = text.length
|
||||||
ta.setSelectionRange l, l
|
ta.setSelectionRange l, l
|
||||||
ta.focus()
|
ta.focus()
|
||||||
|
keydown: (e) ->
|
||||||
|
return unless e.keyCode is 13 and @value #enter, captcha filled
|
||||||
|
return if $('textarea', qr.el).value or $('[type=file]', qr.el).files.length #not blank
|
||||||
|
e.preventDefault()
|
||||||
|
{captcha} = QR
|
||||||
|
captcha.response = @value
|
||||||
|
captchas = $.get 'captchas', []
|
||||||
|
captchas.push captcha
|
||||||
|
$.set 'captchas', captchas
|
||||||
|
@value = ''
|
||||||
|
Recaptcha.reload()
|
||||||
|
@nextSibling.textContent = captchas.length + ' captchas'
|
||||||
submit: (e) ->
|
submit: (e) ->
|
||||||
$('#challenge', qr.el).value = QR.captcha.challenge
|
$('#challenge', qr.el).value = QR.captcha.challenge
|
||||||
$('#response', qr.el).value = $('#recaptcha_response_field', qr.el).value
|
$('#response', qr.el).value = $('#recaptcha_response_field', qr.el).value
|
||||||
@ -1015,7 +1032,6 @@ QR =
|
|||||||
data = JSON.stringify {textContent, href}
|
data = JSON.stringify {textContent, href}
|
||||||
parent.postMessage data, '*'
|
parent.postMessage data, '*'
|
||||||
location = 'about:blank'
|
location = 'about:blank'
|
||||||
|
|
||||||
receive: (e) ->
|
receive: (e) ->
|
||||||
{data} = e
|
{data} = e
|
||||||
if data
|
if data
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user