summaryrefslogtreecommitdiff
path: root/public/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/game.js22
-rw-r--r--public/javascripts/util.js28
2 files changed, 44 insertions, 6 deletions
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 = $("<div>");
this.el.addClass("cursor");
this.el.css('background-image', 'url(' + cursor_image + '?' + Math.floor(Math.random() * 1000) + ')');
- this.el.html("<span>" + user.firstname + "</span>")
+
+ this.name = $("<div>");
+ this.name.html( user.firstname );
+
+ this.time = $("<div>");
+ this.time.html( "0:00" );
+
+ this.el.append(this.name);
+ this.el.append(this.time);
+
$("#cursors").append(this.el);
}
diff --git a/public/javascripts/util.js b/public/javascripts/util.js
index cd1e0c9..86c8328 100644
--- a/public/javascripts/util.js
+++ b/public/javascripts/util.js
@@ -30,4 +30,32 @@ function timeInWords (time) {
if (seconds[1].length == 1) seconds[1] = seconds[1] + "0";
str.push( pluralize( seconds[0] + "." + seconds[1], "second" ) );
return str.join(", ");
+}
+
+function timeInSecs (time) {
+ var str = [];
+ time /= 1000;
+ if (time > 86400) {
+ str.push( leading( time / 86400 ) );
+ }
+ if (time > 3600) {
+ str.push( leading( (time / 3600) % 24 ) );
+ }
+ if (time > 60) {
+ str.push( leading( (time / 60) % 60 ) );
+ }
+ str.push( leading( time % 60 ) );
+
+/*
+ var seconds = Math.floor(10 * (time % 60)) / 10;
+ seconds = (seconds + "").split(".");
+ if (seconds.length == 1) seconds[1] = "0";
+ str.push( leading( time % 60 ) + "." + seconds[1] );
+*/
+
+ return str.join(":");
+}
+function leading(num) {
+ num = Math.floor(num);
+ return num < 10 ? "0" + num : num;
} \ No newline at end of file