Skip to content

Instantly share code, notes, and snippets.

@danwrong
Created September 30, 2009 15:47
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 danwrong/198192 to your computer and use it in GitHub Desktop.
Save danwrong/198192 to your computer and use it in GitHub Desktop.
jQuery(function($) {
var SERVICES = {
'twitpic.com': function(path) {
var code = path.match(/\/([a-zA-Z0-9]+)/)[1];
return "http://twitpic.com/show/thumb/" + code;
}
};
var expression = $.keys(SERVICES).join('|');
var imageLinks = $("a[href*='" + expression + "']");
function findService(hostname) {
$.each($.keys(SERVICES), function(i, service) {
if (hostname.indexOf(service) > 0)
return service;
});
}
function showImage(link) {
var service = findService(link.host);
var thumbnailURL = SERVICES[service](link.pathname);
var img = new Image();
img.src = thumbnailURL;
img.onload = function() {
$(this.element).parents('div.tweet').find('.imagebin').append(img);
}
}
$(document).onscroll(function() {
$.each(imageLinks, function(link) {
if ((window.scrollY + window.innerHeight + 100) >= $(link).offset().top)
showImage(link);
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment