Skip to content

Instantly share code, notes, and snippets.

@arigesher
Created May 1, 2014 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arigesher/586c217e913b462ef0e5 to your computer and use it in GitHub Desktop.
Save arigesher/586c217e913b462ef0e5 to your computer and use it in GitHub Desktop.
embeddable javascript file that will dynamically resize the height on flickr embeds to remove all black space and fit them into the container.
var waitForJquery = function(dofn, interval) {
if(typeof $ === 'function') {
dofn();
} else {
setTimeout(function() {
if(typeof $ === 'function'){
dofn();
} else {
waitForJquery(dofn, interval);
}
}, interval);
}
};
waitForJquery(function() {
$(document).ready(function() {
$("div.flickrEmbeds iframe").each(function(index) {
var ratio = $(this).height() / $(this).width();
var origHeight = $(this).height();
var origWidth = $(this).width();
var self = this;
$(window).resize(function() {
if($(self).parent().width() > origWidth) {
$(self).width(origWidth);
$(self).height(origHeight);
} else {
$(self).width($(self).parent().width());
$(self).height($(self).parent().width() * ratio);
}
});
});
$(window).resize();
});
}, 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment