var tout; function redo_events(provider) { $('.captcha .captcha_text, textarea[id="body"]').off("focus").one("focus", function() { actually_load_captcha(provider); }); } function actually_load_captcha(provider) { $('.captcha .captcha_text, textarea[id="body"]').off("focus"); if (tout !== undefined) { clearTimeout(tout); } $.getJSON(provider, {mode: 'get'}, function(json) { $(".captcha .captcha_cookie").val(json.cookie); $(".captcha .captcha_html").html(json.captchahtml); setTimeout(function() { redo_events(provider); }, json.expires_in * 1000); }); } function load_captcha(provider) { $(function() { $(".captcha>td").html(""+ ""+ "
"); $("#quick-reply .captcha .captcha_text").prop("placeholder", _("Verification")); $(".captcha .captcha_html").on("click", function() { actually_load_captcha(provider); }); $(document).on("ajax_after_post", function() { actually_load_captcha(provider); }); redo_events(provider); $(window).on("quick-reply", function() { redo_events(provider); $("#quick-reply .captcha .captcha_html").html($("form:not(#quick-reply) .captcha .captcha_html").html()); $("#quick-reply .captcha .captcha_cookie").val($("form:not(#quick-reply) .captcha .captcha_cookie").html()); $("#quick-reply .captcha .captcha_html").on("click", function() { actually_load_captcha(provider); }); }); }); }