Skip to content

Instantly share code, notes, and snippets.

@trevorturk
Created February 1, 2011 17:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trevorturk/806218 to your computer and use it in GitHub Desktop.
Save trevorturk/806218 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