Skip to content

Instantly share code, notes, and snippets.

@bs
Created September 30, 2009 16:14
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 bs/198210 to your computer and use it in GitHub Desktop.
Save bs/198210 to your computer and use it in GitHub Desktop.
inline media
jQuery(function($) {
$.extend({
keys: function(obj) {
var a = [];
$.each(obj, function(k){ a.push(k) });
return a;
}
});
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) {
var keys = $.keys(SERVICES);
for(var i=0; i < keys.length; i++) {
if (hostname.indexOf(keys[i]) >= 0) {
return keys[i];
}
}
}
function showImage($link) {
link = $link.get(0);
var service = findService(link.host);
var thumbnailURL = SERVICES[service](link.pathname);
console.log(thumbnailURL);
var img = new Image();
img.src = thumbnailURL;
$link.parents('li.status').append(img);
$link.data('eiDone', true);
}
$(window).scroll(function() {
$(imageLinks).each( function() {
var $link = $(this);
console.log('before render: ' + !$link.data('eiDone'));
if (((window.scrollY + window.innerHeight + 100) >= $link.offset().top) && !$link.data('eiDone')) {
showImage($link);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment