Mercurial > hg > nodescore
diff www/m/js/nodescore-client.js @ 38:ea8d61c851c0
added chat server and more work on interface
author | tzara <rc-web@kiben.net> |
---|---|
date | Wed, 22 Aug 2012 12:51:28 +0000 |
parents | c4719d1b7633 |
children | 3ba24da53406 |
line wrap: on
line diff
--- a/www/m/js/nodescore-client.js Sun Aug 19 22:29:24 2012 +0000 +++ b/www/m/js/nodescore-client.js Wed Aug 22 12:51:28 2012 +0000 @@ -19,7 +19,7 @@ $(".metrocase > div").each(function(){$(this).stop()}); $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)}); $(".metrocase > div").each(function(){$(this).text(" ")}); - $(".metrocase > div").each(function(){$(this).animate({opacity: 0.6}, + $(".metrocase > div").each(function(){$(this).animate({opacity: 1}, 50, function() { $(this).animate({opacity:0.0}); } ); @@ -57,19 +57,35 @@ function countinClient(groupID, currentseconds,mm,text,colour,background){ var groupPage=document.getElementById('group').value if (groupID == groupPage) { - document.getElementById("countinnumber").style.visibility="visible"; - document.getElementById("countinnumber").style.visibility="visible"; - $("#countinnumber").text(currentseconds); - $("#countinnumber").css('background-color', background); + document.getElementById("count").style.visibility="visible"; + document.getElementById("count").style.visibility="visible"; + + $("#counttitle").text(text); + $("#count").text(currentseconds); + //$("#cnt").text(currentseconds); + + $("#count").css('background-color', background); - document.getElementById("countinnumber").style.color=colour; + document.getElementById("count").style.color=colour; - if ( currentseconds == 0) { - document.getElementById("countinnumber").style.visibility='hidden'; - } +// if ( currentseconds == 0) { + //document.getElementById("midcomms").style.visibility='hidden'; +// } + }} +///////////////////////////////////////////////// + +///////////////////////////////////////////////// +// countdown to change + +socket.on("counterText", counterText); +function counterText(groupID, currentseconds,text){ + var groupPage=document.getElementById('group').value + if (groupID == groupPage) { + console.log() + $("#totalcountdown").text(text); }} -///////////////////////////////////////////////// +/////////////////////////////////////// function pageFlip(unit) { console.log("flipping page:"+ unit); @@ -77,7 +93,6 @@ } - ///////////////////////////////////////////////// // call the fancy jquery functions @@ -112,7 +127,8 @@ //////////////////////////////////////////////// -/* +/* commented out for now as interferes with chat +need to introduce metakey...manyana... not so usefull anyway really... keyboard controls +++++++++++++++++++++++++ @@ -122,7 +138,7 @@ s to toggle visibilty of stopwatch h to hide all above -*/ + function toggle_visibility(id) { var e = document.getElementById(id); @@ -158,6 +174,8 @@ } }); +*/ + //////////////////////////////////////////////// // this needs to have a variable to define the websocket // otherwise we will pings from all sockets connected @@ -177,4 +195,64 @@ function getLatencies(x) { socket.emit("getLatencies", x); } -////////////////////////////////////////////// \ No newline at end of file +////////////////////////////////////////////// + + +socket.on('connect', function () { + $('#chat').addClass('connected'); +}); + +socket.on('announcement', function (msg) { + $('#lines').append($('<p>').append($('<em>').text(msg))); +}); + +socket.on('nicknames', function (nicknames) { + $('#nicknames').empty().append($('<span>Online: </span>')); + for (var i in nicknames) { + $('#nicknames').append($('<b>').text(nicknames[i])); + } +}); + +socket.on('user message', message); +socket.on('reconnect', function () { + $('#lines').remove(); + message('System', 'Reconnected to the server'); +}); + +socket.on('reconnecting', function () { + message('System', 'Attempting to re-connect to the server'); +}); + +socket.on('error', function (e) { + message('System', e ? e : 'A unknown error occurred'); +}); + +function message (from, msg) { + $('#lines').append($('<p>').append($('<b>').text(from), msg)); +} + +// dom manipulation +$(function () { + $('#set-nickname').submit(function (ev) { + socket.emit('nickname', $('#nick').val(), function (set) { + if (!set) { + clear(); + return $('#chat').addClass('nickname-set'); + } + $('#nickname-err').css('visibility', 'visible'); + }); + return false; + }); + + $('#send-message').submit(function () { + message('me', $('#message').val()); + socket.emit('user message', $('#message').val()); + clear(); + $('#lines').get(0).scrollTop = 10000000; + return false; + }); + + function clear () { + $('#message').val('').focus(); + }; +}); \ No newline at end of file