Created
October 5, 2011 19:53
-
-
Save dalethedeveloper/1265499 to your computer and use it in GitHub Desktop.
Very Lazy Loading of Facebook Connect with jQuery
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
/* | |
Use jQuery to load FB Connect javascript asynchronously, then trigger manual parsing of individual XFBML tags | |
*/ | |
window.fbAsyncInit = function() { | |
FB.init({channelUrl:'http://YOUR_SITE_URL.HERE/channel.html',xfbml: false,logging:false,status:false}); | |
}; | |
(function() { | |
jQuery(document).ready(function() { | |
jQuery.getScript('http://connect.facebook.net/en_US/all.js', function(){ | |
var parseXFBML = function() { | |
var me = jQuery(this); | |
if (typeof me.data('xfbml') === 'undefined') { | |
FB.XFBML.parse(this); | |
me.data('xfbml','parsed'); | |
} | |
}; | |
jQuery.map( | |
['activity','add-profile-tab','bookmark','comments','friendpile','like','like-box','live-stream','login-button','recommendations','serverFbml','profile-pic','user-status'], | |
function(xfbml){ jQuery('fb\\:'+xfbml).closest('div').each( parseXFBML ); } | |
// XFBML elements (<fb:like-box>) do not behave like real DOMElements | |
// they throw a TypeError: Object [object Object] has no method 'getElementsByTagName' | |
// when plugged directly in eg. FB.XFBML.parse( jQuery('fb\\:like') ); | |
// Thus we have to pass the nearest ancestor element, hedging on a div. | |
); | |
}); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some Internet Explorer Issues
Solution, using conditional includes from HTML5 Boilerplate: