From c15f0f8f6127554f5ddf05718de568c7d3a7dbc5 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 24 Jan 2013 15:33:23 -0500 Subject: idling yourself --- public/javascripts/game.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'public/javascripts/game.js') diff --git a/public/javascripts/game.js b/public/javascripts/game.js index dc69682..cb51987 100644 --- a/public/javascripts/game.js +++ b/public/javascripts/game.js @@ -15,7 +15,7 @@ var game = { if (window._id) { socket.emit('joined', JSON.stringify({ "id": window._id })); own_cursor = new Cursor({ - firstName: "you" + firstname: "you" }); own_cursor.el.addClass("own"); game.bindEvents(); @@ -53,19 +53,18 @@ var game = { }, bindEvents: function(){ - game.cursor = new Cursor ({ - firstname: "you", - }); window.onblur = function () { $("#really_waiting").html("BLUR"); socket.emit('blur', { id: _id }); blurTime = Date.now(); afk = true; + own_cursor.el.addClass('idle'); } window.onfocus = function () { $("#really_waiting").html("FOCUS"); socket.emit('focus', { id: _id }); afk = false; + own_cursor.el.removeClass('idle'); if (blurTime) { delay += (Date.now() - blurTime); $("#reset").html( "You left the page for " + timeInWords(delay) + ", counting it against your score.." ); @@ -91,7 +90,9 @@ var UI = { start = now; } var howlong = Math.floor( (now - start) ) - delay; - $("#waiting").html( timeInWords( howlong ) ); + if (own_cursor) { + $("#waiting").html( timeInSecs( howlong ) ); + } } else { if (blurTime) { $("#reset").html( "You left the page for " + timeInWords(now - blurTime) + ", counting it against your score.." ); @@ -138,6 +139,15 @@ function Cursor ( user ) { this.el = $("
"); this.el.addClass("cursor"); this.el.css('background-image', 'url(' + cursor_image + '?' + Math.floor(Math.random() * 1000) + ')'); - this.el.html("" + user.firstname + "") + + this.name = $("
"); + this.name.html( user.firstname ); + + this.time = $("
"); + this.time.html( "0:00" ); + + this.el.append(this.name); + this.el.append(this.time); + $("#cursors").append(this.el); } -- cgit v1.2.3-70-g09d2