Created
February 3, 2011 22:44
-
-
Save ternel/810382 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
<!doctype html> | |
<html> | |
<head> | |
<title>TwitterWall Justin Bieber</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> | |
<script src="./socket.io.js"></script> | |
<script type='text/javascript'> | |
// Création du client Socket.io et connexion | |
var socket = new io.Socket('codingevening.projects.clever-age.net', {port: 8080}); | |
socket.connect(); | |
// Certains tweets sont envoyés en plusieurs morceaux par la Streaming API | |
// Concaténation des réponses et parseJSON pour avoir le tweet complet. | |
var buffer = ''; | |
socket.on('message', function(serverdata) { | |
buffer = buffer + serverdata; | |
try | |
{ | |
var data = jQuery.parseJSON(buffer); | |
pushNewTweet(data); | |
buffer = ''; | |
} | |
catch(e) | |
{} | |
}); | |
socket.on('connect', function() { $('#status').html('Connexion établie'); }); | |
function pushNewTweet(tweet) | |
{ | |
var p = $("<div class='tweet' style='display:none'><div class='content'><a class='main-screenname' href='http://www.twitter.com/" + | |
tweet.user.screen_name + "/status/" + tweet.id + "' target='_blank'> " + | |
tweet.user.screen_name + "</a> " + tweet.text + "</div></div>"); | |
if($('#tweets div.tweet').size() > 15) { | |
$('#tweets div.tweet:last').slideDown(100, function() { | |
$(this).remove(); | |
}); | |
} | |
$('#tweets').prepend(p); | |
p.slideDown(140); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="tweets"> | |
<span id="status">En attente de la connexion.</span> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment