Skip to content

Instantly share code, notes, and snippets.

@deian
Created June 7, 2013 00:04
Show Gist options
  • Save deian/5726093 to your computer and use it in GitHub Desktop.
Save deian/5726093 to your computer and use it in GitHub Desktop.
example of how to do comments
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.10.1.min.js" type="text/javascript"> </script>
</head>
<body>
<div class="comment" id="post-123">
<blockquote>
Some great comment
</blockquote>
<button class="reply-button">Reply</button>
</div>
<div class="comment" id="post-124">
<blockquote>
Some leet comment
</blockquote>
<button class="reply-button">Reply</button>
</div>
<script type="text/javascript">
$(".reply-button").click(function() {
var parent = $(this).parent()[0];
var id = parent.id; // in reply to
var reply_button = $(this);
reply_button.hide(); //hide reply button
var form =
$('<form action="#">'+
'<input type="hidden" name="post" value=\"' + id + '\"/>'+
'<input type="text" name="comment" placeholder="Comment..."/>'+
'<input type="submit" value="Reply"/>'+
'</form>').appendTo(parent);
form.submit(function() {
// actually send ajax request
console.log("sending request : "+form.serialize());
// this should be in ajax success and error callbacks:
reply_button.show(); // show button
$(this).remove(); //delete form
return false;
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment