Permalink
Browse files

Add 'N users' link

  • Loading branch information...
1 parent e8380ec commit 12458124a80faf2b866805e4236531fc8043b313 @ry ry committed Jun 5, 2009
Showing with 17 additions and 6 deletions.
  1. +10 −4 client.js
  2. +2 −1 index.html
  3. +5 −1 style.css
View
@@ -6,21 +6,27 @@ var CONFIG = { debug: false
var nicks = [];
+function updateUsersLink ( ) {
+ $("#usersLink").text(nicks.length.toString() + " users");
+}
+
function userJoin(nick, timestamp) {
addMessage(nick, "joined", timestamp, "join");
for (var i = 0; i < nicks.length; i++)
if (nicks[i] == nick) return;
nicks.push(nick);
+ updateUsersLink();
}
function userPart(nick, timestamp) {
addMessage(nick, "left", timestamp, "part");
for (var i = 0; i < nicks.length; i++) {
if (nicks[i] == nick) {
nicks.splice(i,1)
- return;
+ break;
}
}
+ updateUsersLink();
}
// utility functions
@@ -263,21 +269,21 @@ function onConnect (session) {
showChat(CONFIG.nick);
}
-function who (callback) {
+function who () {
jQuery.get("/who", {}, function (data, status) {
if (status != "success") return;
nicks = data.nicks;
var nick_string = nicks.length > 0 ? nicks.join(", ") : "(none)";
-
addMessage("users:", nick_string, new Date(), "notice");
- if (callback) callback();
}, "json");
}
$(document).ready(function() {
$("#entry").keypress(handleKeyPress);
+ $("#usersLink").click(who);
+
$("#connectButton").click(function () {
showLoad();
var nick = $("#nickInput").attr("value");
View
@@ -204,8 +204,9 @@
<ul id="status">
<li class="date" id="currentTime">12:59</li>
<li id="nick">chat</li>
+ <li><a id="usersLink" href="#">5 users</a></li>
</ul>
- <input tabindex="1" type="text" id="entry" />
+ <input tabindex="1" type="text" id="entry"/>
</div>
</body>
</html>
View
@@ -103,5 +103,9 @@ a:hover { text-decoration: underline; color: #aaa; }
#toolbar li {
display: block;
float: left;
- margin: 0 0.5em 0 0;
+ margin: 0 2em 0 0;
+}
+
+#usersLink {
+ color: inherit;
}

0 comments on commit 1245812

Please sign in to comment.