Extend arrow key navigation to noscript captcha.

This commit is contained in:
ccd0 2015-06-20 19:33:48 -07:00
parent d34944e1c4
commit 83ce9c1cfe

View File

@ -48,8 +48,11 @@ Captcha.fixes =
$.on d, 'keydown', @keybinds.bind(@) $.on d, 'keydown', @keybinds.bind(@)
initNoscript: -> initNoscript: ->
@noscript = true
@images = $$ '.fbc-payload-imageselect > input'
$.addStyle @cssNoscript $.addStyle @cssNoscript
@addLabels() @addLabels()
$.on d, 'keydown', @keybinds.bind(@)
fixImages: -> fixImages: ->
@images = $$ '.rc-imageselect-target > div' @images = $$ '.rc-imageselect-target > div'
@ -59,7 +62,7 @@ Captcha.fixes =
addLabels: -> addLabels: ->
imageSelect = $ '.fbc-payload-imageselect' imageSelect = $ '.fbc-payload-imageselect'
labels = for checkbox, i in $$ 'input', imageSelect labels = for checkbox, i in @images
checkbox.id = "checkbox-#{i}" checkbox.id = "checkbox-#{i}"
label = $.el 'label', label = $.el 'label',
htmlFor: checkbox.id htmlFor: checkbox.id
@ -70,13 +73,19 @@ Captcha.fixes =
keybinds: (e) -> keybinds: (e) ->
return unless @images and doc.contains(@images[0]) and d.activeElement return unless @images and doc.contains(@images[0]) and d.activeElement
reload = $.id 'recaptcha-reload-button' reload = $ '#recaptcha-reload-button, .fbc-button-reload'
verify = $.id 'recaptcha-verify-button' verify = $ '#recaptcha-verify-button, .fbc-button-verify > input'
x = @images.indexOf d.activeElement x = @images.indexOf d.activeElement
if x < 0 if x < 0
return unless $('.rc-controls').contains d.activeElement if d.activeElement is verify
x = if d.activeElement is verify then 11 else 9 x = 11
if e.keyCode is 32 and x < 9 # space on image else if $('.rc-controls, .fbc-buttons').contains d.activeElement
x = 9
else
return
if !@noscript and e.keyCode is 32 and x < 9 # space on image
@images[x].click() @images[x].click()
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()