Guest User

Untitled

a guest
May 10th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // JavaScript Document
  2. jQuery(function(){
  3. // Execute this code when the page is ready to work
  4. // Create a Script Tag
  5.  var script = document.createElement('script');
  6.  script.type = 'text/javascript';
  7.  script.src = "http://search.twitter.com/search.json?&q=%23life&callback=initialize&rpp=27&_="+ new Date().getTime();
  8. // Add the Script to the Body element, which will in turn load the script and run it.
  9.  $("body").append(script);
  10. });
  11.  
  12. function initialize(jsonData){
  13.     var time = setInterval( function(){
  14.         getNewTweets()
  15.     }, 2000);
  16.    
  17.     processTheseTweets(jsonData);  
  18. }
  19.  
  20. function getNewTweets(){
  21.     $.ajax({
  22.         url: "http://search.twitter.com/search.json?&q=%23life&&callback=initialize&rpp=27&lang&result_type=recent&_="+ new Date().getTime(),
  23.         dataType: 'jsonp',
  24.         jsonpCallback: "processTheseTweets"
  25.     });
  26. }
  27.  
  28. function processTheseTweets(jsonData){
  29.  
  30.     x = 1;
  31.     var shtml = '';
  32.     var results = jsonData.results;
  33.     if(results){
  34.         // if there are results (it should be an array), loop through it with a jQuery function
  35.         $.each(results, function(index,value){
  36.             shtml += "<p class='content'><span class='author'>" + x + ". " + value.from_user + "</span>: " +
  37.             value.text + "<span class='date'>" + value.created_at + "</span></p>";
  38.             x = x+1;
  39.    
  40.        
  41.         });
  42.  
  43.         // Load the HTML in the .tweet_stream div
  44.          $(".tweet_stream").html( shtml );
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment