Skip to content

Instantly share code, notes, and snippets.

@richleland
Created May 17, 2012 16:53
Show Gist options
  • Save richleland/2720168 to your computer and use it in GitHub Desktop.
Save richleland/2720168 to your computer and use it in GitHub Desktop.
discovery specific comments config
$(function() {
// set up some references
var commentsDiv = $("#comments");
var commentsToggle = $("#comments-toggle");
if(commentsDiv.length && typeof commentsCategoryID !== "undefined" && typeof commentsStreamID !== "undefined") {
// comment counter
// docs at http://developers.gigya.com/020_Client_API/020_Methods/z_020_Comments/comments.getComments
gigya.comments.getComments({
categoryID: commentsCategoryID,
streamID: commentsStreamID,
callback: function(response) {
$('.comment-count').text(response.commentCount);
}
});
// comments UI
// docs at http://developers.gigya.com/020_Client_API/020_Methods/socialize.showCommentsUI
gigya.socialize.showCommentsUI({
// required params
categoryID: commentsCategoryID,
streamID: commentsStreamID,
containerID: 'comments',
// optional params
cid:'',
enabledShareProviders: 'facebook,twitter,yahoo,linkedin',
width: '100%',
// event handlers
onCommentSubmitted: function(eventObj) {
var commentCounts = $('.comment-count');
if(commentCounts.length) {
var currentCount = parseInt(commentCounts.eq(0).text(), 10);
commentCounts.text(currentCount + 1);
}
},
onLoad: function(eventObj) {
// hide the comments initially
commentsDiv.hide();
}
});
// comments toggle
var closedText = "Post or View Comments";
var openText = "Hide Comments";
if(commentsToggle.length) {
// set the initial text for the toggler
commentsToggle.text(closedText);
// tell the toggle what to do when clicked
commentsToggle.on("click", function(e) {
var textToShow = commentsToggle.text() == closedText ? openText : closedText;
commentsDiv.toggle();
commentsToggle.text(textToShow);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment