Created
October 1, 2009 18:21
-
-
Save danwrong/199146 to your computer and use it in GitHub Desktop.
This file contains hidden or 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($) { | |
if (typeof $.keys != 'function') { | |
$.extend({ | |
keys: function(obj) { | |
var a = []; | |
$.each(obj, function(k){ a.push(k) }); | |
return a; | |
} | |
}); | |
} | |
var services, imageLinks; | |
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); | |
var img = new Image(); | |
img.src = thumbnailURL; | |
// Will need a little bit of work here to add any extra markup/classes | |
$link.parents('li.status').append(img); | |
$link.data('eiDone', true); | |
} | |
function showNearbyImages() { | |
$(imageLinks).each( function() { | |
var $link = $(this); | |
// need to IE equivs for scrollY/innerHeight here | |
if (((window.scrollY + window.innerHeight + 100) >= $link.offset().top) && | |
!$link.data('eiDone')) { | |
showImage($link); | |
} | |
}); | |
} | |
$.twitter = $.twitter || {}; | |
$.extend($.twitter, { | |
updateEmbeddedImages: function() { | |
var expression = $.map($.keys(services), function(service) { | |
return "a[href*='" + service + "']" | |
}).join(', '); | |
imageLinks = $(expression); | |
}, | |
embedImages: function(imageServices) { | |
services = imageServices; | |
$.twitter.updateEmbeddedImages(); | |
$(window).scroll(showNearbyImages); | |
showNearbyImages(); | |
} | |
}) | |
}); | |
jQuery.twitter.embedImages({ | |
'twitpic.com': function(path) { | |
var code = path.match(/\/([a-zA-Z0-9]+)/)[1]; | |
return "http://twitpic.com/show/thumb/" + code; | |
}, | |
'yfrog': function(path) { | |
var code = path.match(/\/([a-zA-Z0-9]+)/)[1]; | |
return "http://yfrog.com/" + code + ".th.jpg"; | |
} | |
}); | |
// When page updated with more tweets have it generate a custom event then... | |
// $(document).bind('twitter_tweetsloaded', $.twitter.updateEmbeddedImages); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment