Skip to content

Instantly share code, notes, and snippets.

@erainey
Created September 29, 2012 18:52
Show Gist options
  • Save erainey/3804888 to your computer and use it in GitHub Desktop.
Save erainey/3804888 to your computer and use it in GitHub Desktop.
JavaScript: Facebook Social Plugins jQuerified
(function($) {
$.fn.xfbmlParse = function() {
FB.XFBML.parse(document.getElementById(this));
return this
};
$.fn.fbActivityFeed = function(options) {
var activityFeedSettings = {site:window.location, width:"300", height:"300", header:true, colorscheme:"light", font:"arial", border_color:"", recommendations:false, filter:" ", ref:" "};
return this.each(function() {
if(options) {
$.extend(activityFeedSettings, options)
}
var activityFeed = '<fb:activity site="' + activityFeedSettings.site + '" width="' + activityFeedSettings.width + '" height="' + activityFeedSettings.height + '" header="' + activityFeedSettings.header + '" colorscheme="' + activityFeedSettings.colorscheme + '" font="' + activityFeedSettings.font + '" border_color="' + activityFeedSettings.border_color + '" recommendations="' + activityFeedSettings.recommendations + '" filter="' + activityFeedSettings.filter + '" ref="' + activityFeedSettings.ref +
'"></fb:activity>';
$(this).html(activityFeed);
FB.XFBML.parse(document.getElementById(this))
})
};
$.fn.fbComments = function(options) {
var commentSettings = {href:window.location, numPosts:"2", width:"500", commentCreate:false, commentRemove:false};
return this.each(function() {
if(options) {
$.extend(commentSettings, options)
}
if(commentSettings.commentCreate != false) {
FB.Event.subscribe("comment.create", function() {
$(commentSettings.commentCreate)
})
}
if(commentSettings.commentRemove != false) {
FB.Event.subscribe("comment.remove", function() {
$(commentSettings.commentRemove)
})
}
var commentBox = '<fb:comments href="' + commentSettings.href + '" num_posts="' + commentSettings.numPosts + '" width="' + commentSettings.width + '"></fb:comments>';
$(this).html(commentBox);
FB.XFBML.parse(document.getElementById(this))
})
};
$.fn.fbFacepile = function(options) {
var facepileSettings = {href:window.location, width:"200", max_rows:"1"};
return this.each(function() {
if(options) {
$.extend(facepileSettings, options)
}
var facepile = '<fb:facepile href="' + facepileSettings.href + '" width="' + facepileSettings.width + '" max_rows="' + facepileSettings.max_rows + '"></fb:facepile>';
$(this).html(facepile);
FB.XFBML.parse(document.getElementById(this))
})
};
$.fn.fbLike = function(options) {
var likeSettings = {href:window.location, layout:"standard", showFaces:"true", width:"450", action:"like", font:"Arial", colorScheme:"light", edgeCreate:false, edgeRemove:false};
return this.each(function() {
if(options) {
$.extend(likeSettings, options)
}
if(likeSettings.edgeCreate != false) {
FB.Event.subscribe("edge.create", function() {
$(likeSettings.edgeCreate)
})
}
if(likeSettings.edgeRemove != false) {
FB.Event.subscribe("edge.remove", function() {
$(likeSettings.edgeRemove)
})
}
var likeButton = '<fb:like href="' + likeSettings.href + '" layout="' + likeSettings.layout + ' " show_faces="' + likeSettings.showFaces + '" width="' + likeSettings.width + '" font="' + likeSettings.font + '" colorscheme="' + likeSettings.colorScheme + '" action="' + likeSettings.action + '"></fb:like>';
$(this).html(likeButton);
FB.XFBML.parse(document.getElementById(this))
})
};
$.fn.fbLikeBox = function(options) {
var likeBoxSettings = {href:"http://www.facebook.com/platform", width:"292", height:"427", colorscheme:"light", show_faces:true, header:true, stream:true};
return this.each(function() {
if(options) {
$.extend(likeBoxSettings, options)
}
var likeBox = '<fb:like-box href="' + likeBoxSettings.href + '" width="' + likeBoxSettings.width + '" height="' + likeBoxSettings.height + '" header="' + likeBoxSettings.header + '" colorscheme="' + likeBoxSettings.colorscheme + '" show_faces="' + likeBoxSettings.show_faces + '" stream="' + likeBoxSettings.stream + '"></fb:like-box>';
$(this).html(likeBox);
FB.XFBML.parse(document.getElementById(this))
})
};
$.fn.fbLoginButton = function(options) {
var loginSettings = {showFaces:"true", width:"200", maxRows:"1", message:" ", size:" ", perms:" ", authLogin:false, authLogout:false};
return this.each(function() {
if(options) {
$.extend(loginSettings, options)
}
if(loginSettings.authLogin != false) {
FB.Event.subscribe("auth.login", function() {
$(loginSettings.authLogin)
})
}
if(loginSettings.authLogout != false) {
FB.Event.subscribe("auth.logout", function() {
$(loginSettings.authLogout)
})
}
var loginButton = '<fb:login-button show-faces="' + loginSettings.showFaces + '" width="' + loginSettings.width + '" max-rows="' + loginSettings.maxRows + '" perms="' + loginSettings.perms + '" size="' + loginSettings.size + '"></fb:login-button>';
$(this).html(loginButton);
FB.XFBML.parse(document.getElementById(this))
})
};
$.fn.fbRecommendations = function(options) {
var recommendationsSettings = {site:window.location, width:"300", height:"300", header:true, colorscheme:"light", font:"arial", border_color:"", ref:" "};
return this.each(function() {
if(options) {
$.extend(recommendationsSettings, options)
}
var recommendations = '<fb:recommendations site="' + recommendationsSettings.site + '" width="' + recommendationsSettings.width + '" height="' + recommendationsSettings.height + '" header="' + recommendationsSettings.header + '" colorscheme="' + recommendationsSettings.colorscheme + '" font="' + recommendationsSettings.font + '" border_color="' + recommendationsSettings.border_color + '" ref="' + recommendationsSettings.ref + '"></fb:recommendations>';
$(this).html(recommendations);
FB.XFBML.parse(document.getElementById(this))
})
};
$.fn.fbSend = function(options) {
var sendSettings = {href:window.location, layout:"standard", font:"Arial", colorScheme:"light", ref:" ", messageSend:false};
return this.each(function() {
if(options) {
$.extend(sendSettings, options)
}
if(sendSettings.messageSend != false) {
FB.Event.subscribe("message.send", function() {
$(sendSettings.messageSend)
})
}
var sendButton = '<fb:send href="' + sendSettings.href + '" font="' + sendSettings.font + '" colorscheme="' + sendSettings.colorScheme + '" ref="' + sendSettings.ref + '"></fb:send>';
$(this).html(sendButton);
FB.XFBML.parse(document.getElementById(this))
})
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment