annotate www/m/js/nodescore-slides.js @ 59:5ba250832739

css visibility and counter fixes
author tzara <rc-web@kiben.net>
date Tue, 02 Apr 2013 15:14:25 +0000
parents 474c1ad1e811
children e868cdd4b3e9
rev   line source
rc-web@42 1 /////////////////////////////////////////////////
rc-web@42 2 // connect to websocket
rc-web@42 3
rc-web@42 4 var socket = io.connect();
rc-web@42 5
rc-web@42 6 //socket.on("metroPulse", metronomeTick);
rc-web@42 7 /////////////////////////////////////////////////
rc-web@42 8 socket.on("metroPulse", pulseInClient);
rc-web@42 9 function pulseInClient(pulse,groupID,metrobeat){
rc-web@42 10 var groupPage=document.getElementById('group').value
rc-web@42 11 if (groupID == groupPage) {
rc-web@42 12 metronomeTick(1000, groupID, metrobeat);
rc-web@42 13 }
rc-web@42 14 }
rc-web@42 15 /////////////////////////////////////////////////
rc-web@42 16 function metroCss(beat, beatcolor,text){
rc-web@42 17 var color = beatcolor;
rc-web@42 18
rc-web@42 19 $(".metrocase > div").each(function(){$(this).stop()});
rc-web@42 20 $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)});
rc-web@42 21 $(".metrocase > div").each(function(){$(this).text(" ")});
rc-web@42 22 // $(".metrocase > div").each(function(){$(this).animate({color: blue},
rc-web@42 23 // 50,
rc-web@42 24 // function() { $(this).animate({color:red}); }
rc-web@42 25 // );
rc-web@42 26 // })
rc-web@42 27 }
rc-web@42 28
rc-web@42 29 function metronomeTick(pulse, voice,metrobeat) {
rc-web@42 30 var color = "gray"
rc-web@42 31 metroCss(0, "red", "4")
rc-web@42 32 setTimeout(function(){metroCss(0, "black", "4")},150);
rc-web@42 33 };
rc-web@42 34
rc-web@42 35 /////////////////////////////////////////////////
rc-web@42 36
rc-web@42 37 // update the stopwatch value on the client page in line with server
rc-web@42 38 socket.on("chronFromServer", function(chron) {
rc-web@42 39 $("div#client_chronometer").text(chron);
rc-web@42 40 });
rc-web@42 41
rc-web@42 42
rc-web@42 43 // server time
rc-web@42 44
rc-web@42 45 //var groupPage=document.getElementById('group').value
rc-web@42 46 //if (groupID == groupPage) {
rc-web@42 47 socket.on("dateTime", function(datetime) {
rc-web@42 48 $("div#datetime").text("" +datetime);
rc-web@42 49
rc-web@42 50 });
rc-web@42 51
rc-web@42 52 /////////////////////////////////////////////////
rc-web@42 53 // countdown to change
rc-web@42 54
rc-web@42 55 socket.on("countinFromServer", countinClient);
rc-web@58 56 function countinClient(groupID, currentseconds,mm,text,colour,background,unit){
rc-web@42 57 var groupPage=document.getElementById('group').value
rc-web@59 58 if (groupID == groupPage) {
rc-web@59 59 //document.getElementById("count").style.visibility="visible";
rc-web@59 60 //document.getElementById("midcomms").style.visibility="visible";
rc-web@59 61 $("#counttitle").css('color','white');
rc-web@59 62 $("#counttitle").text(text);
rc-web@58 63 // in box
rc-web@58 64 //$('#sqr'+unit).text(currentseconds);
rc-web@59 65 $("#count").text(currentseconds);
rc-web@58 66 //$("#cnt").text(currentseconds);
rc-web@58 67
rc-web@59 68 $("#count").css('background-color', background);
rc-web@59 69 document.getElementById("count").style.color=colour;
rc-web@59 70 if ( currentseconds == 0) {
rc-web@58 71 //document.getElementById("midcomms").style.visibility='hidden';
rc-web@59 72 }
rc-web@59 73 }}
rc-web@42 74 /////////////////////////////////////////////////
rc-web@42 75
rc-web@42 76 /////////////////////////////////////////////////
rc-web@42 77 // countdown to change
rc-web@42 78
rc-web@42 79 socket.on("counterText", cText);
rc-web@42 80 function cText(groupID, currentseconds,text){
rc-web@58 81 $("#totalcountdown"+groupID).text(text);
rc-web@42 82 var groupPage=document.getElementById('group').value
rc-web@42 83 if (groupID == groupPage) {
rc-web@42 84 //console.log(text)
rc-web@42 85 $("#totalcountdown").text(text);
rc-web@42 86 }}
rc-web@42 87
rc-web@42 88 ///////////////////////////////////////
rc-web@42 89 function pageFlip(unit) {
rc-web@59 90
rc-web@42 91 $('#sections').trigger('goto', [parseFloat(unit)]);
rc-web@42 92 }
rc-web@42 93
rc-web@42 94 /////////////////////////////////////////////////
rc-web@42 95 // call the fancy jquery functions
rc-web@54 96 //function slideTo (target) { $('#sections').trigger('goto', [target]); }
rc-web@42 97 function pad2(number) { return (number < 10 ? '0' : '') + number }
rc-web@42 98
rc-web@42 99 /////////////////////////////////////////////////
rc-web@54 100 //var testSound = new buzz.sound( 'audio/testfile', { formats: [ 'ogg', 'mp3' ] } );
rc-web@42 101 socket.on("pageFlipfromserver", pageTurn);
rc-web@42 102 function pageTurn (group,unit,time,mm) {
rc-web@42 103 var groupPage=document.getElementById('group').value;
rc-web@42 104 if (group == groupPage) {
rc-web@42 105 var g= pad2(group);
rc-web@42 106 var p= pad2(unit);
rc-web@42 107 // pageFlip(unit);
rc-web@42 108 pageTurnB(unit)
rc-web@54 109
rc-web@42 110 }
rc-web@42 111 else {
rc-web@58 112 //console.log("not for this group... ignoring... for group:" + group );
rc-web@42 113 }
rc-web@42 114 }
rc-web@42 115
rc-web@42 116 function pageTurnB(unit) {
rc-web@42 117 var units=6;
rc-web@42 118 var next=(((unit+1)%units)+units)%units
rc-web@59 119 $("#live").load("music.html #"+unit +" *");
rc-web@43 120 $("#preview").html("<h3 style='background:transparent; position: relative; font-size:1.5em;top:14px; left:10px;';> n e x t : </h3><img src='thumbs/"+next + ".png" + "' width='315'>")
rc-web@42 121 }
rc-web@42 122
rc-web@42 123 ////////////////////////////////////////////////
rc-web@42 124
rc-web@42 125 /* commented out for now as interferes with chat
rc-web@42 126 need to introduce metakey...manyana... not so usefull anyway really...
rc-web@42 127
rc-web@42 128 keyboard controls
rc-web@42 129 +++++++++++++++++++++++++
rc-web@42 130
rc-web@42 131 SPACE to toggle visibilty of preview
rc-web@42 132 m to toggle visibilty of metronome
rc-web@42 133 s to toggle visibilty of stopwatch
rc-web@42 134 h to hide all above
rc-web@42 135
rc-web@42 136
rc-web@42 137 */
rc-web@42 138 function toggle_visibility(id) {
rc-web@42 139 var e = document.getElementById(id);
rc-web@42 140 if(e.style.display == 'block')
rc-web@42 141 e.style.display = 'none';
rc-web@42 142 else
rc-web@42 143 e.style.display = 'block';
rc-web@42 144 }
rc-web@42 145
rc-web@42 146 $(document).keypress(function(e){
rc-web@42 147 // "space bar" for next unit preview
rc-web@42 148 var checkWebkitandIE=(e.which==32 ? 1 : 0);
rc-web@42 149 var checkMoz=(e.which==32 ? 1 : 0);
rc-web@42 150 // "m" button for metronome
rc-web@42 151 var mcheckWebkitandIE=(e.which==109 ? 1 : 0);
rc-web@42 152 var mcheckMoz=(e.which==109 ? 1 : 0);
rc-web@42 153 // "s" button for stopwatch/chronometer
rc-web@42 154 var ccheckWebkitandIE=(e.which==115 ? 1 : 0);
rc-web@42 155 var ccheckMoz=(e.which==115 ? 1 : 0);
rc-web@42 156
rc-web@42 157 // "h" button for hideall
rc-web@42 158 var hcheckWebkitandIE=(e.which==104 ? 1 : 0);
rc-web@42 159 var hcheckMoz=(e.which==104 ? 1 : 0);
rc-web@42 160
rc-web@42 161 // console.log(e.which);
rc-web@42 162 // if (checkWebkitandIE || checkMoz) { toggle_visibility('preview') }
rc-web@42 163 // if (mcheckWebkitandIE || mcheckMoz) { toggle_visibility('comms') }
rc-web@42 164 // if (ccheckWebkitandIE || ccheckMoz) { toggle_visibility('client_chronometer') }
rc-web@42 165 if (hcheckWebkitandIE || hcheckMoz) {
rc-web@42 166 toggle_visibility('info')
rc-web@42 167 //toggle_visibility('comms')
rc-web@42 168 //toggle_visibility('preview')
rc-web@42 169 }
rc-web@42 170 });
rc-web@42 171
rc-web@42 172 //*/
rc-web@42 173
rc-web@42 174 ////////////////////////////////////////////////
rc-web@42 175 // this needs to have a variable to define the websocket
rc-web@42 176 // otherwise we will pings from all sockets connected
rc-web@42 177 // no! the server broadcasts the ping and the clients emit the pong!
rc-web@42 178 // ah but then the time reported back from the server needs to be targeted
rc-web@42 179 // to specific client..
rc-web@42 180 //////////////////////////////////////////////
rc-web@42 181 // Latency "Pong"
rc-web@49 182 socket.on("timeFromServer", function(n) {
rc-web@49 183 socket.emit("clientTimeResponse",n); });
rc-web@42 184
rc-web@42 185 socket.on("latencyFromServer", function(latency) {
rc-web@42 186 $("#client_latency").text("Latency: "+latency+"ms.")
rc-web@59 187
rc-web@42 188 });
rc-web@42 189
rc-web@42 190 function getLatencies(x) { socket.emit("getLatencies", x); }
rc-web@42 191
rc-web@42 192 //////////////////////////////////////////////
rc-web@42 193
rc-web@42 194
rc-web@42 195 socket.on('connect', function () {
rc-web@42 196 $('#chat').addClass('connected');
rc-web@42 197 });
rc-web@42 198
rc-web@42 199 socket.on('announcement', function (msg) {
rc-web@42 200 $('#lines').append($('<p>').append($('<em>').text(msg)));
rc-web@42 201 });
rc-web@42 202
rc-web@42 203 socket.on('nicknames', function (nicknames) {
rc-web@42 204 $('#nicknames').empty().append($('<span>Online: </span>'));
rc-web@42 205 for (var i in nicknames) {
rc-web@42 206 $('#nicknames').append($('<b>').text(nicknames[i]));
rc-web@42 207 }
rc-web@42 208 });
rc-web@42 209
rc-web@42 210 socket.on('user message', message);
rc-web@42 211 socket.on('reconnect', function () {
rc-web@42 212 $('#lines').remove();
rc-web@42 213 message('System', 'Reconnected to the server');
rc-web@42 214 });
rc-web@42 215
rc-web@42 216 socket.on('reconnecting', function () {
rc-web@42 217 message('System', 'Attempting to re-connect to the server');
rc-web@42 218 });
rc-web@42 219
rc-web@42 220 socket.on('error', function (e) {
rc-web@42 221 message('System', e ? e : 'A unknown error occurred');
rc-web@42 222 });
rc-web@42 223
rc-web@42 224 function message (from, msg) {
rc-web@42 225 $('#lines').append($('<p>').append($('<b>').text(from), msg));
rc-web@42 226 }
rc-web@42 227
rc-web@42 228 // dom manipulation
rc-web@42 229 $(function () {
rc-web@42 230 $('#set-nickname').submit(function (ev) {
rc-web@42 231 socket.emit('nickname', $('#nick').val(), function (set) {
rc-web@42 232 if (!set) {
rc-web@42 233 clear();
rc-web@42 234 return $('#chat').addClass('nickname-set');
rc-web@42 235 }
rc-web@42 236 $('#nickname-err').css('visibility', 'visible');
rc-web@42 237 });
rc-web@42 238 return false;
rc-web@42 239 });
rc-web@42 240
rc-web@42 241 $('#send-message').submit(function () {
rc-web@42 242 message('me', $('#message').val());
rc-web@42 243 socket.emit('user message', $('#message').val());
rc-web@42 244 clear();
rc-web@42 245 $('#lines').get(0).scrollTop = 10000000;
rc-web@42 246 return false;
rc-web@42 247 });
rc-web@42 248
rc-web@42 249 function clear () {
rc-web@42 250 $('#message').val('').focus();
rc-web@42 251 };
rc-web@42 252 });