(function($) {
jQuery.fn.autoResizeFbPost = function() {
var fixWidth = function($container, $clonedContainer, doParse) {
// default parameter.
doParse = typeof doParse == 'undefined' ? true : doParse;
var updatedWidth = $container.width();
// update all div.fb-post with correct width of container
$clonedContainer
.find('div.fb-post')
.each(function() {
$(this).attr('data-width', updatedWidth);
});
// update page with adjusted markup
$container.html( $clonedContainer.html() );
// should we call FB.XFBML.parse? we don't want to do this at page load because it will happen automatically
if (doParse && FB && FB.XFBML && FB.XFBML.parse)
FB.XFBML.parse();
};
return this.each(function() {
var $container = $(this),
$clonedContainer = $container.clone();
// make sure there is a .fb-post element before we do anything.
if ( ! $container.find('div.fb-post').length) {
return false;
}
// execute once (document.ready) and do not call FB.XFBML.parse()
fixWidth($container, $clonedContainer, false);
// on window resize, update and fix..
$(window).on('resize', function() {
// only trigger fixWidth once after window has not been resized for 1 second
delayFireOnce(1000).done(function() {
fixWidth($container, $clonedContainer);
});
});
// helper function
var delayTimer;
var delayFireOnce = function(timeout) {
var d = $.Deferred();
clearTimeout(delayTimer);
t = setTimeout(function() {
d.resolve();
}, timeout);
return d.promise();
};
});
};
})(jQuery);
(function($) {
$(document).ready(function() {
$('#post').autoResizeFbPost();
});
})(jQuery);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.