This commit is contained in:
James Campos 2011-09-02 00:37:51 -07:00
parent f3366e0a8a
commit 288fede1ca
2 changed files with 87 additions and 87 deletions

View File

@ -1248,31 +1248,38 @@
time: Date.now() time: Date.now()
}; };
}, },
node: function(root) { captchaPush: function(el) {
var quote; var captcha, captchas;
quote = $('a.quotejs + a', root); captcha = QR.captcha;
return $.bind(quote, 'click', QR.quote); captcha.response = el.value;
captchas = $.get('captchas', []);
captchas.push(captcha);
$.set('captchas', captchas);
el.value = '';
Recaptcha.reload();
return el.nextSibling.textContent = captchas.length + ' captchas';
}, },
quote: function(e) { captchaShift: function() {
var i, ss, ta, text, v; var captcha, captchas, cutoff;
e.preventDefault(); captchas = $.get('captchas', []);
text = ">>" + this.textContent + "\n"; cutoff = Date.now() - 5 * HOUR + 5 * MINUTE;
if (!QR.el) { while (captcha = captchas.shift()) {
QR.dialog(text); if (captcha.time > cutoff) {
return; break;
}
} }
ta = $('textarea', QR.el); $.set('captchas', captchas);
v = ta.value; return captcha;
ss = ta.selectionStart;
ta.value = v.slice(0, ss) + text + v.slice(ss);
i = ss + text.length;
ta.setSelectionRange(i, i);
return ta.focus();
}, },
close: function() { close: function() {
$.rm(QR.el); $.rm(QR.el);
return QR.el = null; return QR.el = null;
}, },
node: function(root) {
var quote;
quote = $('a.quotejs + a', root);
return $.bind(quote, 'click', QR.quote);
},
dialog: function(text) { dialog: function(text) {
var el, l, ta; var el, l, ta;
if (text == null) { if (text == null) {
@ -1301,28 +1308,30 @@
e.preventDefault(); e.preventDefault();
return QR.captchaPush(this); return QR.captchaPush(this);
}, },
captchaPush: function(el) { quote: function(e) {
var captcha, captchas; var i, ss, ta, text, v;
captcha = QR.captcha; e.preventDefault();
captcha.response = el.value; text = ">>" + this.textContent + "\n";
captchas = $.get('captchas', []); if (!QR.el) {
captchas.push(captcha); QR.dialog(text);
$.set('captchas', captchas); return;
el.value = ''; }
Recaptcha.reload(); ta = $('textarea', QR.el);
return el.nextSibling.textContent = captchas.length + ' captchas'; v = ta.value;
}, ss = ta.selectionStart;
captchaShift: function() { ta.value = v.slice(0, ss) + text + v.slice(ss);
var captcha, captchas, cutoff; i = ss + text.length;
captchas = $.get('captchas', []); ta.setSelectionRange(i, i);
cutoff = Date.now() - 5 * HOUR + 5 * MINUTE; return ta.focus();
while (captcha = captchas.shift()) { },
if (captcha.time > cutoff) { receive: function(e) {
break; var data;
} data = e.data;
if (data) {
return $.extend($('a.error', QR.el), JSON.parse(data));
} else {
return QR.close();
} }
$.set('captchas', captchas);
return captcha;
}, },
submit: function(e) { submit: function(e) {
var captcha, challenge, el, response; var captcha, challenge, el, response;
@ -1352,15 +1361,6 @@
parent.postMessage(data, '*'); parent.postMessage(data, '*');
return location = 'about:blank'; return location = 'about:blank';
}); });
},
receive: function(e) {
var data;
data = e.data;
if (data) {
return $.extend($('a.error', QR.el), JSON.parse(data));
} else {
return QR.close();
}
} }
}; };
qr = { qr = {

View File

@ -978,25 +978,29 @@ QR =
QR.captcha = QR.captcha =
challenge: c challenge: c
time: Date.now() time: Date.now()
node: (root) -> captchaPush: (el) ->
quote = $ 'a.quotejs + a', root {captcha} = QR
$.bind quote, 'click', QR.quote captcha.response = el.value
quote: (e) -> captchas = $.get 'captchas', []
e.preventDefault() captchas.push captcha
text = ">>#{@textContent}\n" $.set 'captchas', captchas
if not QR.el el.value = ''
QR.dialog text Recaptcha.reload()
return el.nextSibling.textContent = captchas.length + ' captchas'
ta = $ 'textarea', QR.el captchaShift: ->
v = ta.value captchas = $.get 'captchas', []
ss = ta.selectionStart cutoff = Date.now() - 5*HOUR + 5*MINUTE
ta.value = v[0...ss] + text + v[ss..] while captcha = captchas.shift()
i = ss + text.length if captcha.time > cutoff
ta.setSelectionRange i, i break
ta.focus() $.set 'captchas', captchas
captcha
close: -> close: ->
$.rm QR.el $.rm QR.el
QR.el = null QR.el = null
node: (root) ->
quote = $ 'a.quotejs + a', root
$.bind quote, 'click', QR.quote
dialog: (text='') -> dialog: (text='') ->
QR.el = el = ui.dialog 'qr', top: '0', left: '0', " QR.el = el = ui.dialog 'qr', top: '0', left: '0', "
<a class=close title=close>X</a><input type=checkbox id=autohide title=autohide> <a class=close title=close>X</a><input type=checkbox id=autohide title=autohide>
@ -1029,23 +1033,25 @@ QR =
return if $('textarea', QR.el).value or $('[type=file]', QR.el).files.length #not blank return if $('textarea', QR.el).value or $('[type=file]', QR.el).files.length #not blank
e.preventDefault() e.preventDefault()
QR.captchaPush @ QR.captchaPush @
captchaPush: (el) -> quote: (e) ->
{captcha} = QR e.preventDefault()
captcha.response = el.value text = ">>#{@textContent}\n"
captchas = $.get 'captchas', [] if not QR.el
captchas.push captcha QR.dialog text
$.set 'captchas', captchas return
el.value = '' ta = $ 'textarea', QR.el
Recaptcha.reload() v = ta.value
el.nextSibling.textContent = captchas.length + ' captchas' ss = ta.selectionStart
captchaShift: -> ta.value = v[0...ss] + text + v[ss..]
captchas = $.get 'captchas', [] i = ss + text.length
cutoff = Date.now() - 5*HOUR + 5*MINUTE ta.setSelectionRange i, i
while captcha = captchas.shift() ta.focus()
if captcha.time > cutoff receive: (e) ->
break {data} = e
$.set 'captchas', captchas if data
captcha $.extend $('a.error', QR.el), JSON.parse data
else
QR.close()
submit: (e) -> submit: (e) ->
$('.error', qr.el).textContent = '' $('.error', qr.el).textContent = ''
if (el = $('#recaptcha_response_field', QR.el)).value if (el = $('#recaptcha_response_field', QR.el)).value
@ -1064,12 +1070,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) ->
{data} = e
if data
$.extend $('a.error', QR.el), JSON.parse data
else
QR.close()
qr = qr =
# TODO # TODO