Created
September 30, 2009 16:14
-
-
Save bs/198210 to your computer and use it in GitHub Desktop.
inline media
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($) { | |
$.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