From 5de4f5dd0f565a52271a58a06b8daa17f0461f01 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 15 Mar 2011 12:57:28 +0100 Subject: Provide some simple text feedback while calculating the Hashcash proof of work. --- static-files/js/comment-submission.js | 38 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'static-files') diff --git a/static-files/js/comment-submission.js b/static-files/js/comment-submission.js index 59db100..c4c3d6a 100644 --- a/static-files/js/comment-submission.js +++ b/static-files/js/comment-submission.js @@ -18,21 +18,33 @@ jQuery(function($) { url: "/RPC/generate-transaction-key", dataType: 'json', success: function(tkey) { - form.find(':submit').attr("disabled", true); var salt = 0; var text = form.find('textarea').val().replace(/\s+/g, ""); - while (!acceptable_cashhash(Sha256.hash(text + ":" + tkey + ":" + salt))) { - salt++; - } - form.prepend(''); - form.prepend(''); - form_augmented_p = true; - form.find(':submit').removeAttr("disabled"); - $('.comment-form').submit(); - form.submit(); - console.log("tkey = " + tkey); - console.log("salt = " + salt); - console.log("Submitted!"); + var submit_button = form.find(':submit'); + var status_message; + submit_button.after('Calculating Hashcash...'); + status_message = form.find('.hashcash-status-message'); + status_message.fadeOut(0); + status_message.fadeIn(200); + submit_button.attr("disabled", true); + var tryHashcash = function () { + var tryRightNow = 1000; + while (!acceptable_cashhash(Sha256.hash(text + ":" + tkey + ":" + salt))) { + salt++; + tryRightNow--; + if (tryRightNow === 0) { + setTimeout(tryHashcash, 0); + return; + } + } + form.prepend(''); + form.prepend(''); + form_augmented_p = true; + //submit_button.removeAttr("disabled"); + $('.comment-form').submit(); + form.submit(); + }; + setTimeout(tryHashcash, 0); } }); return false; -- cgit v1.2.3