Created
October 9, 2012 05:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
CoffeeScript is my new <3 :)
Super helpful. Thank you!
Grreat, ty for saving time!
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.
Thx <3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GitHub needs a 'like' button (liked for coffeescript!)