Skip to content

Instantly share code, notes, and snippets.

@aroc
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aroc/a0175669102bec44ea28 to your computer and use it in GitHub Desktop.
Save aroc/a0175669102bec44ea28 to your computer and use it in GitHub Desktop.
SideComments listening to events example.
// Listen to "commentPosted", and send a request to your backend to save the comment.
// More about this event in the "docs" section.
sideComments.on('commentPosted', function( comment ) {
$.ajax({
url: '/comments',
type: 'POST'
data: comment,
success: function( savedComment ) {
// Once the comment is saved, you can insert the comment into the comment stream with "insertComment(comment)".
sideComments.insertComment(comment);
}
});
});
// Listen to "commentDeleted" and send a request to your backend to delete the comment.
// More about this event in the "docs" section.
sideComments.on('commentDeleted', function( commentId ) {
$.ajax({
url: '/comments/' + commentId,
type: 'DELETE',
success: function( success ) {
// Do something.
}
});
});
@egyptianbman
Copy link

Hey, this needs a few updates:

  • commentPosted needs to inject a comment.id before running insertComment(comment).
  • commentDeleted event needs to receive a comment object, not commentId.

Thanks for the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment