More cleanup & formatting
[dylansserver.git] / includes / ajax.js
index 50541dc..bc51be3 100644 (file)
@@ -1,4 +1,5 @@
 $(document).ready(function() {
+  $('#recaptcha_widget').show();
   $('.submit').click(function() {
     if ($('#comment_text').val() != '') {
         var challenge = Recaptcha.get_challenge();
@@ -14,6 +15,7 @@ $(document).ready(function() {
               var name = $("#comment_name").val();
               var email = $("#comment_email").val();
               var text = $("#comment_text").val();
+                  if (name == '') { name = "anon" }
            var comment_data = { "captcha" : "passed",
                                        "name" : name,
                                 "email" : email,
@@ -25,11 +27,17 @@ $(document).ready(function() {
                         url: "verify",
                         data: comment_data,
                         success: function() {
+                          var new_post = "<h3><a href='mailto:" + email
+                                          + "'>" + name + "</a></h3>"
+                                                          + text + "<br><br>";
+                          $('#comments').prepend(new_post);
+                          $('#comment').hide();
                           console.log('posted new comment');
                         }
                   });
                 } else {
-                  console.log('reCAPTCHA said you\'re not human.');
+           var error = "<span style='font-weight:bold;font-family:sans-serif;color:red;margin-top:15px;'>reCAPTCHA said you're not human</span>";
+                  $('#comment').append(error);
                 }
        },
           error: function() {
@@ -40,7 +48,8 @@ $(document).ready(function() {
           }
      }); 
        } else {
-         console.log('but you didn\'t write anything!');
+      var error = "<span style='font-weight:bold;font-family:sans-serif;color:red;margin-top:15px;'>but you didn't write anything!<br></span>";
+         $('#submit').before(error);
        }
        return false;
   });