diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 1e9547730..7fb4b5bf1 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -1,10 +1,12 @@ Main = init: -> if location.hostname is 'www.google.com' - type = if location.pathname is '/recaptcha/api/fallback' then 'noscript' else 'v2' return $.ready -> doc = d.documentElement - Captcha[type].initFrame() + if location.pathname is '/recaptcha/api/fallback' + Captcha.noscript.initFrame() + else + Captcha.fixes.init() g.threads = new SimpleDict() g.posts = new SimpleDict() diff --git a/src/Posting/Captcha.fixes.coffee b/src/Posting/Captcha.fixes.coffee new file mode 100644 index 000000000..868da4785 --- /dev/null +++ b/src/Posting/Captcha.fixes.coffee @@ -0,0 +1,36 @@ +Captcha.fixes = + selectors: + image: '.rc-imageselect-target > .rc-imageselect-tile > img' + + init: -> + switch location.pathname.split('/')[3] + when 'anchor' then @initMain() + when 'frame' then @initPopup() + + initMain: -> + $.onExists d.body, '#recaptcha-anchor', true, (checkbox) -> + focus = -> + if d.hasFocus() and d.activeElement isnt checkbox + checkbox.focus() + focus() + $.on window, 'focus', -> + $.queueTask focus + + initPopup: -> + $.addStyle "#{@selectors.image}:focus {outline: 2px solid #4a90e2;}" + @fixImages() + new MutationObserver(=> @fixImages()).observe d.body, {childList: true, subtree: true} + + fixImages: -> + return unless (images = $$ @selectors.image).length + focus = images[0].tabIndex isnt 0 + for img in images + img.tabIndex = 0 + @focusImage images[0] if focus + + focusImage: (img) -> + # XXX Image is not focusable at first in Firefox; to be refactored when I figure out why. + $.asap -> + img.focus() + d.activeElement is img or not doc.contains img + , -> diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 8dc9c78fb..3b694940e 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -25,36 +25,6 @@ Captcha.v2 = # XXX Greasemonkey 1.x workaround to gain access to GM_* functions. $.queueTask => @save false - initFrame: -> - @initFrame2[location.pathname.split('/')[3]]() - - initFrame2: - anchor: -> - $.onExists d.body, '#recaptcha-anchor', true, (checkbox) -> - focus = -> - if d.hasFocus() and d.activeElement isnt checkbox - checkbox.focus() - focus() - $.on window, 'focus', -> - $.queueTask focus - - frame: -> - selector = '.rc-imageselect-target > .rc-imageselect-tile > img' - $.addStyle "#{selector}:focus {outline: 2px solid #4a90e2;}" - fixImages = -> - return unless (images = $$ selector).length - focus = images[0].tabIndex isnt 0 - for img in images - img.tabIndex = 0 - if focus - # XXX Image is not focusable at first in Firefox; to be refactored when I figure out why. - $.asap -> - images[0].focus() - d.activeElement is images[0] or not doc.contains images[0] - , -> - fixImages() - new MutationObserver(fixImages).observe d.body, {childList: true, subtree: true} - shouldFocus: false timeouts: {} postsCount: 0