function FBCommentBox(fbBaseControl, entityType, entityId, userId)
{
var _this = this;
var _fbBaseControl = fbBaseControl;
var _entityType = entityType;
var _entityId = entityId;
var _userId = userId;
this.Ready = function ()
{
$(_fbBaseControl).bind('OnFBAPIInitialize', _this.FBInitialize);
}
this.FBInitialize = function ()
{
FB.Event.subscribe('comment.create', _this.OnCommentCreate);
FB.Event.subscribe('comment.remove', _this.OnCommentRemove);
}
this.OnCommentCreate = function (response)
{
// user has added a comment
var commentId = response.commentID;
var commentHRef = response.href;
var parentID = response.parentCommentID;
// pass the comment ID to the server
$.ajax({
type: "GET",
url: "/FBCommentBox.ashx",
data: { 'Event': 'comment.create', 'ID': commentId, 'EntityType': _entityType, 'href': commentHRef, 'EntityId': _entityId, 'UserId': _userId },
contentType: "application/json; charset=utf-8",
success: _this.OnCommentCreated,
error: _this.OnCommentCreatedError
});
}
this.OnCommentRemove = function (response)
{
// user has removed a comment
var commentId = response.commentID;
var commentHRef = response.href;
//alert("Comment remove: ID (" + response.commentId + ") Href(" + response.href + ")");
// pass the comment ID to the server
$.ajax({type: "GET",
url: "/FBCommentBox.ashx",
data: { 'Event': 'comment.remove', 'ID': commentId, 'EntityType': _entityTyp, 'href': commentHRef, 'EntityId': _entityId, 'UserId': _userId },
contentType: "application/json; charset=utf-8",
success: _this.OnCommentRemoved,
error: _this.OnCommentRemovedError
});
}
this.OnCommentCreated = function (fbComment, status, jqXHR)
{
if(fbComment && fbComment.ExternalId)
{
//alert('Message ' + fbComment.ExternalId + ' added - Name: ' + fbComment.Name + ' Date: ' + fbComment.DatePosted + ' Text: ' + fbComment.Body);
}
else
{
//alert("No data returned for created comment.");
}
}
this.OnCommentCreatedError = function (jqXHR, status, error)
{
//alert('Status: ' + status + " Error: " + jqXHR.responseText + " " + error);
}
this.OnCommentRemoved = function (fbComment, status, jqXHR)
{
if(fbComment && fbComment.ExternalId)
{
//alert('Message ' + fbComment.ExternalId + ' removed - Name: ' + fbComment.Name + ' Date: ' + fbComment.DatePosted + ' Text: ' + fbComment.Body);
}
else
{
//alert("No data returned for removed comment.");
}
}
this.OnCommentRemovedError = function (jqXHR, status, error)
{
//alert('Status: ' + status + " Error: " + jqXHR.responseText + " " + error);
}
//
// Ready handler
//
$(document).ready(_this.Ready);
}