Skip to content

Commit

Permalink
Facebook Embeds: Fix async initialization after SDK loaded
Browse files Browse the repository at this point in the history
The SDK calls `window.fbAsyncInit` immediately after initializing.

See: https://github.com/Automattic/io/issues/382

Merges r118115-wpcom.
  • Loading branch information
Andrew Duthie authored and zinigor committed May 18, 2015
1 parent 3f567b4 commit 1e1b3b2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions modules/shortcodes/js/facebook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(function( FB ) {
/* global FB */
(function( window ) {
var facebookEmbed = function() {
if ( 'undefined' !== typeof FB && FB.XFBML ) {
FB.XFBML.parse();
Expand All @@ -7,19 +8,22 @@
fbroot.id = 'fb-root';
document.getElementsByTagName( 'body' )[0].appendChild( fbroot );

jQuery.getScript( '//connect.facebook.net/en_US/sdk.js', function() {
FB.init( {
appId : '249643311490',
version: 'v2.3'
} );
FB.XFBML.parse();
} );
jQuery.getScript( '//connect.facebook.net/en_US/sdk.js' );
}
};

window.fbAsyncInit = function() {
FB.init( {
appId : '249643311490',
version: 'v2.3'
} );

FB.XFBML.parse();
};

if ( 'undefined' !== typeof infiniteScroll ) {
jQuery( document.body ).on( 'post-load', facebookEmbed );
}

facebookEmbed();
})();
})( this );

0 comments on commit 1e1b3b2

Please sign in to comment.