angular-easyfb

AngularJS + Facebook JavaScript SDK.
Start from v1.1.0, angular-easyfb adds support for Facebook Platform versioning.
Please check out the new FB JS SDK setup doc if you want to switch platform versions (module default is v2.6).
Features
- Full Facebook JavaScript SDK support
- Seamless FB SDK initialization (asynchronously load script and FB.init)
- All SDK API callbacks are automatically applied with AngularJS context
- Support both callback and $q promise
- Provide built-in directive support for Facebook XFBML plugins
Demos
Getting started
Include the angular-easyfb module with AngularJS script in your page.
Add ezfb to your app module's dependency.
angular;Install with npm
npm install angular-easyfbInstall with Bower
bower install angular-easyfbUsage
ezfb service
Configuration
getLocale / setLocale
Configure the locale of the original FB script file. Default locale is en_US.
angular ;getInitParams / setInitParams
Configure parameters for the original FB.init with ezfbProvider.setInitParams. (See also ezfb.init)
angular ;getInitFunction / setInitFunction
Customize the original FB.init function call with services injection support. The initialization parameters set in setInitParams are available via local injection ezfbInitParams.
// Default init functionvar _defaultInitFunction = '$window' 'ezfbInitParams' { // Initialize the FB JS SDK $windowFB;};Customization example:
angular ;getLoadSDKFunction / setLoadSDKFunction
Customize Facebook JS SDK loading. The function also supports DI, with two more local injections:
ezfbLocale- locale nameezfbAsyncInit- must called to finish the module initialization process
// Default load SDK functionvar _defaultLoadSDKFunction = '$window' '$document' 'ezfbAsyncInit' 'ezfbLocale' { // Load the SDK's source Asynchronously { var js id = 'facebook-jssdk' ref = d0; if d return; js = d; jsid = id; jsasync = true; jssrc = "//connect.facebook.net/" + ezfbLocale + "/sdk.js"; // js.src = "//connect.facebook.net/" + ezfbLocale + "/sdk/debug.js"; // debug refparentNode; }$document0; $windowfbAsyncInit = ezfbAsyncInit;};Customization example:
angular ;ezfb.init
In the case that you don't want to(or you can't) configure your FB.init parameters in configuration phase, you may use ezfb.init in run phase. And any ezfb API call will not run until ezfb.init is called.
angular ;using ezfb
This is the original FB wrapping service, all FB.* APIs are available through ezfb.*.
No need to worry about FB script loading and Angular context applying at all.
angular /** * Inject into controller */; Watch the demo to see it in action.
$q promise support
Support of $q promise create more possibility for ezfb service.
Only the APIs with callback support returning promise.
Combine multiple api calls
$qall ezfb ezfb;Watch the promise version api demo to see it in action.
Social plugins support
Facebook Social Plugins are now supported with built-in directives.
The code copied from the above link will automatically work in angular-easyfb-covered AngularJS apps.
Additionally, you can add an onrender parameter to the social plugin directive. Expressions in the onrender parameter will be evaluated every time the social plugin gets rendered.
Demo (directives demonstration)
Demo2 (interpolated attributes)
Changelog
See the changelog here.
Develop
angular-easyfb uses Grunt to run all the development tasks.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins.
angular-easyfb also uses Bower to manage packages for tests.
Setup
After cloning the git repo to your place, simply run following commands to install required packages.
npm installbower installBuild
Generate a minified js file after running all the tests.
gruntRunning tests
Unit tests:
grunt test:unitTest coverage:
grunt coverage