Created
September 30, 2009 15:47
-
-
Save danwrong/198192 to your computer and use it in GitHub Desktop.
This file contains 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
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