Created
March 9, 2011 07:06
-
-
Save meeech/861805 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
//Update the forrst title bar evey 5 seconds with the | |
//count of users in the chat room. | |
//uses some jq | |
(function(){ | |
var title = $('title'), | |
originalTitleText = title.html(), | |
messageCountFrom = false; | |
var getUserCount = function() { | |
return $('#users-online').children().length; | |
}; | |
//Guess right now, simplest way | |
//If window in focus, | |
var getMessageCount = function() { | |
if(false === messageCountFrom) { | |
return '*'; | |
} | |
//Tried caching $(topic-messsages) but seems i need to call it live eachtime | |
return $('#topic-messages').children().length - messageCountFrom; | |
}; | |
var updateTitle = function(){ | |
title.html('('+getUserCount()+'/'+getMessageCount()+') '+ originalTitleText); | |
}; | |
//No good dom/id hooks right now, but you get the idea... | |
$(window).blur(function() { | |
messageCountFrom = $('#topic-messages').children().length; | |
}); | |
$(window).focus(function() { | |
messageCountFrom = false; | |
updateTitle(); | |
}); | |
updateTitle(); | |
setInterval(updateTitle, 3000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment