Skip to content

Instantly share code, notes, and snippets.

@ElliotChong
Created October 9, 2012 05:45
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElliotChong/3856847 to your computer and use it in GitHub Desktop.
Save ElliotChong/3856847 to your computer and use it in GitHub Desktop.
Angular directives that will parse Facebook plugins added to the DOM after Facebook has been initialized
module = angular.module 'FacebookPluginDirectives', []
createDirective = (name) ->
module.directive name, ->
restrict: 'C'
link: (scope, element, attributes) ->
FB?.XFBML.parse(element.parent()[0])
createDirective pluginName for pluginName in ['fbActivity', 'fbComments', 'fbFacepile', 'fbLike', 'fbLikeBox', 'fbLiveStream', 'fbLoginButton', 'fbName', 'fbProfilePic', 'fbRecommendations']
(function() {
var createDirective, module, pluginName, _i, _len, _ref;
module = angular.module('FacebookPluginDirectives', []);
createDirective = function(name) {
return module.directive(name, function() {
return {
restrict: 'C',
link: function(scope, element, attributes) {
return typeof FB !== "undefined" && FB !== null ? FB.XFBML.parse(element.parent()[0]) : void 0;
}
};
});
};
_ref = ['fbActivity', 'fbComments', 'fbFacepile', 'fbLike', 'fbLikeBox', 'fbLiveStream', 'fbLoginButton', 'fbName', 'fbProfilePic', 'fbRecommendations'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
pluginName = _ref[_i];
createDirective(pluginName);
}
}).call(this);
@bcelenza
Copy link

bcelenza commented Oct 9, 2012

GitHub needs a 'like' button (liked for coffeescript!)

@ElliotChong
Copy link
Author

CoffeeScript is my new <3 :)

@ielashi
Copy link

ielashi commented Aug 24, 2013

Super helpful. Thank you!

@Panda-ref
Copy link

Grreat, ty for saving time!

@l0c0luke
Copy link

I threw a $timeout around the return on line 11 to ensure that this was always displayed correctly. I found that sometimes it would be ok, other times not without the timeout.

@grmxque
Copy link

grmxque commented Feb 11, 2016

Thx <3

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