var greenInjuryClock = { "clock": 0, "clockSnapshot": 0, "clockLastStopped": 0, "clockExpected": 0, "clockState": { "bumpClockUpButton": null, "bumpClockDownButton": null, }, "isClockFlashing": false, "stopClockFlag": false, "reset": function(){ $("#greenInjuryStopClockButton").click(); $("#greenInjuryRewindClockButton").addClass("disabled"); greenInjuryClock.setClock(scoreClock.config.colorClockLengths.greenInjuryLength); }, "bumpClockUp": function() { length = greenInjuryClock.clock + 1; greenInjuryClock.setClock(length); }, "bumpClockDown": function() { if (greenInjuryClock.clock == 0) { $("#greenInjuryBumpClockDownButton").addClass("disabled"); return; } length = greenInjuryClock.clock - 1; greenInjuryClock.setClock(length); }, "flashClock": function() { if (greenInjuryClock.stopClockFlag) { greenInjuryClock.isClockFlashing = false; $("#greenInjuryMinsField").css( "background-color", "rgb(255, 255, 255)"); $("#greenInjurySecsField").css( "background-color", "rgb(255, 255, 255)"); return; } var backgroundColor = $("#greenInjuryMinsField").css( "background-color" ); //window.alert(backgroundColor) if (backgroundColor == "rgb(255, 255, 255)") { $("#greenInjuryMinsField").css( "background-color", "rgb(51, 51, 51)"); $("#greenInjurySecsField").css( "background-color", "rgb(51, 51, 51)"); setTimeout(greenInjuryClock.flashClock, 500); } else if (backgroundColor == "rgb(51, 51, 51)") { $("#greenInjuryMinsField").css( "background-color", "rgb(255, 255, 255)"); $("#greenInjurySecsField").css( "background-color", "rgb(255, 255, 255)"); setTimeout(greenInjuryClock.flashClock, 500); } //window.alert(backgroundColor); }, "rewindClock": function() { if (greenInjuryClock.clockSnapshot > 0) { greenInjuryClock.clockLastStopped = greenInjuryClock.clockSnapshot; greenInjuryClock.setClock(greenInjuryClock.clockSnapshot); } $("#greenInjuryRewindClockButton").addClass("disabled"); }, "setClock": function (length) { greenInjuryClock.clock = length; var min = Math.floor(length / 60); var secs = length % 60; if (secs < 10) { secs = "0" + secs; } $("#greenInjuryMinsField").val(min); $("#greenInjurySecsField").val(secs); scoreClock.syncColorClock("greenInjury", min, secs); }, "startClock": function() { greenInjuryClock.clockState.bumpClockUpButton = $("#greenInjuryBumpClockUpButton").hasClass("disabled") ? "disabled" : "enabled"; greenInjuryClock.clockState.bumpClockUpButton = $("#greenInjuryBumpClockUpButton").hasClass("disabled") ? "disabled" : "enabled"; greenInjuryClock.clockState.bumpClockDownButton = $("#greenInjuryBumpClockDownButton").hasClass("disabled") ? "disabled" : "enabled"; $("#greenInjuryBumpClockUpButton").addClass("disabled"); $("#greenInjuryBumpClockDownButton").addClass("disabled"); $("#greenInjuryRewindClockButton").addClass("disabled"); greenInjuryClock.clockSnapshot = greenInjuryClock.clock; greenInjuryClock.stopClockFlag = false; greenInjuryClock.clockExpected = Date.now() + 1000; setTimeout(greenInjuryClock.stepClock, 1000); }, "stepClock": function() { var dt = Date.now() - greenInjuryClock.clockExpected; // the drift (positive for overshooting) if (dt > 1000) { // something really bad happened. Maybe the browser (tab) was inactive? // possibly special handling to avoid futile "catch up" run } if (!greenInjuryClock.stopClockFlag) { var newLength = greenInjuryClock.clock - 1; if (newLength <= 0 && !greenInjuryClock.isClockFlashing) { greenInjuryClock.isClockFlashing = true; greenInjuryClock.flashClock(); } if (newLength < 0) { return; } greenInjuryClock.setClock(newLength); greenInjuryClock.clockExpected += 1000; setTimeout(greenInjuryClock.stepClock, Math.max(0, 1000 - dt)); // take into account drift } }, "stopClock": function() { if (greenInjuryClock.clockState.bumpClockUpButton != "disabled") { $("#greenInjuryBumpClockUpButton").removeClass("disabled"); } if (greenInjuryClock.clockState.bumpClockUpButton != "disabled") { $("#greenInjuryBumpClockUpButton").removeClass("disabled"); } if (greenInjuryClock.clockState.bumpClockDownButton != "disabled") { $("#greenInjuryBumpClockDownButton").removeClass("disabled"); } if (greenInjuryClock.clockSnapshot > 0) { $("#greenInjuryRewindClockButton").removeClass("disabled"); } greenInjuryClock.clockLastStopped = greenInjuryClock.clock; greenInjuryClock.stopClockFlag = true; }, };