Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@bcelenza bcelenza commented Oct 9, 2012

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

@ElliotChong

This comment has been minimized.

Copy link
Owner Author

@ElliotChong ElliotChong commented Oct 10, 2012

CoffeeScript is my new <3 :)

@ielashi

This comment has been minimized.

Copy link

@ielashi ielashi commented Aug 24, 2013

Super helpful. Thank you!

@Panda-ref

This comment has been minimized.

Copy link

@Panda-ref Panda-ref commented Sep 6, 2013

Grreat, ty for saving time!

@l0c0luke

This comment has been minimized.

Copy link

@l0c0luke l0c0luke commented Sep 18, 2013

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

This comment has been minimized.

Copy link

@grmxque 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
You can’t perform that action at this time.