Advertisement
Guest User

Untitled

a guest
Dec 1st, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. jQuery(function($) {
  2. var SERVICES = {
  3. 'twitpic.com': function(path) {
  4. var code = path.match(/\/([a-zA-Z0-9]+)/)[1];
  5.  
  6. return "http://twitpic.com/show/thumb/" + code;
  7. }
  8. };
  9.  
  10. var expression = $.keys(SERVICES).join('|');
  11. var imageLinks = $("a[href*='" + expression + "']");
  12.  
  13. function findService(hostname) {
  14. $.each($.keys(SERVICES), function(i, service) {
  15. if (hostname.indexOf(service) > 0)
  16. return service;
  17. });
  18. }
  19.  
  20. function showImage(link) {
  21. var service = findService(link.host);
  22. var thumbnailURL = SERVICES[service](link.pathname);
  23.  
  24. var img = new Image();
  25. img.src = thumbnailURL;
  26. img.onload = function() {
  27. $(this.element).parents('div.tweet').find('.imagebin').append(img);
  28. }
  29. }
  30.  
  31. $(document).onscroll(function() {
  32. $.each(imageLinks, function(link) {
  33. if ((window.scrollY + window.innerHeight + 100) >= $(link).offset().top)
  34. showImage(link);
  35. })
  36. });
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement