From c85aebbceb020b44bb9bd02bb84793135ca2bcce Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 5 Sep 2019 18:55:13 -0700 Subject: [PATCH] Provide a visual indication that the captcha is loading. --- src/Posting/Captcha.cache.coffee | 11 ++++++++++- src/Posting/Captcha.v2.coffee | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Posting/Captcha.cache.coffee b/src/Posting/Captcha.cache.coffee index 444e477ef..b425dd91d 100644 --- a/src/Posting/Captcha.cache.coffee +++ b/src/Posting/Captcha.cache.coffee @@ -37,6 +37,7 @@ Captcha.cache = if !$.event('RequestCaptcha', {isReply}) @prerequested = true @submitCB = @save.bind(@) + @updateCount() haveCookie: -> /\b_ct=/.test(d.cookie) and QR.posts[0].thread isnt 'new' @@ -53,17 +54,21 @@ Captcha.cache = request: (isReply) -> if !@submitCB return if $.event('RequestCaptcha', {isReply}) - (cb) => @submitCB = cb + (cb) => + @submitCB = cb + @updateCount() abort: -> if @submitCB delete @submitCB $.event 'AbortCaptcha' + @updateCount() saveAPI: (captcha) -> if (cb = @submitCB) delete @submitCB cb captcha + @updateCount() else @save captcha @@ -74,6 +79,7 @@ Captcha.cache = QR.captcha.setup(d.activeElement is QR.nodes.status) delete @submitCB cb() + @updateCount() save: (captcha) -> if (cb = @submitCB) @@ -97,4 +103,7 @@ Captcha.cache = clearTimeout @timer if @captchas.length @timer = setTimeout @clear.bind(@), @captchas[0].timeout - Date.now() + @updateCount() + + updateCount: -> $.event 'CaptchaCount', @captchas.length diff --git a/src/Posting/Captcha.v2.coffee b/src/Posting/Captcha.v2.coffee index 4b7e3565b..41fcf41f4 100644 --- a/src/Posting/Captcha.v2.coffee +++ b/src/Posting/Captcha.v2.coffee @@ -181,7 +181,8 @@ Captcha.v2 = count: -> count = Captcha.cache.getCount() - @nodes.counter.textContent = "Captchas: #{count}" + loading = if Captcha.cache.submitCB then '...' else '' + @nodes.counter.textContent = "Captchas: #{count}#{loading}" @moreNeeded() reload: ->