Skip to content

Instantly share code, notes, and snippets.

@hooopo
Forked from trevorturk/gist:806218
Created February 26, 2011 19:19
Show Gist options
  • Save hooopo/845517 to your computer and use it in GitHub Desktop.
Save hooopo/845517 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
var focus = true;
var count = 0;
var title = document.title;
$(window).focus(function(){
focus = true;
count = 0;
setTimeout(function(){
document.title = title;
}, 500);
});
$(window).blur(function(){
focus = false;
});
var pusher = new Pusher('your_api_key');
var channel = pusher.subscribe('messages');
channel.bind('messages', function(data){
$('#messages').prepend(data); // specific to your app
if (focus == false) {
count++;
setTimeout(function(){
document.title = '(' + count + ') ' + title;
}, 500);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment