Possibly support copy+paste version of captcha that appears sometimes.

(I haven't been able to test it yet.)
This commit is contained in:
ccd0 2014-12-09 02:09:33 -08:00
parent 1d9b252c44
commit bb806b4538

View File

@ -25,7 +25,7 @@ QR.captcha =
subtree: true subtree: true
$.on counter, 'click', @toggle.bind @ $.on counter, 'click', @toggle.bind @
$.on window, 'captcha:success', @save.bind @ $.on window, 'captcha:success', => @save false
shouldFocus: false shouldFocus: false
timeouts: {} timeouts: {}
@ -76,14 +76,21 @@ QR.captcha =
afterSetup: (mutations) -> afterSetup: (mutations) ->
for mutation in mutations for mutation in mutations
for node in mutation.addedNodes for node in mutation.addedNodes
iframe = node if node.nodeName is 'IFRAME' @setupIFrame node if node.nodeName is 'IFRAME'
return unless iframe @setupTextArea node if node.nodeName is 'TEXTAREA'
return
setupIFrame: (iframe) ->
@setupTime = Date.now()
if QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight if QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight
QR.nodes.el.style.top = null QR.nodes.el.style.top = null
QR.nodes.el.style.bottom = '0px' QR.nodes.el.style.bottom = '0px'
iframe.focus() if @shouldFocus iframe.focus() if @shouldFocus
@shouldFocus = false @shouldFocus = false
setupTextArea: (textarea) ->
$.one textarea, 'input', => @save true
destroy: -> destroy: ->
return unless @isEnabled return unless @isEnabled
delete @timeouts.destroy delete @timeouts.destroy
@ -106,17 +113,20 @@ QR.captcha =
else else
null null
save: (e) -> save: (pasted) ->
response = $('textarea', @nodes.container).value
timeout = (if pasted then @setupTime else Date.now()) + 2 * $.MINUTE
if QR.cooldown.auto and @needed() if QR.cooldown.auto and @needed()
@shouldFocus = true @shouldFocus = true
@reload() @reload()
else else
QR.nodes.status.focus() QR.nodes.status.focus()
@timeouts.destroy ?= setTimeout @destroy.bind(@), 3 * $.SECOND if pasted
@destroy()
else
@timeouts.destroy ?= setTimeout @destroy.bind(@), 3 * $.SECOND
$.forceSync 'captchas' $.forceSync 'captchas'
@captchas.push @captchas.push {response, timeout}
response: e.detail
timeout: Date.now() + 2 * $.MINUTE
@count() @count()
$.set 'captchas', @captchas $.set 'captchas', @captchas