Skip to content

Commit

Permalink
Fixed clock
Browse files Browse the repository at this point in the history
  • Loading branch information
gsingh93 committed May 10, 2016
1 parent 3ae6e59 commit 96364c6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 52 deletions.
1 change: 0 additions & 1 deletion src/static/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,6 @@ module.exports = {
});

function levelsFilterChange() {
var $this = $(this);
var category_filter = $('select[name="category_filter"] option:selected')[0].value;
var status_filter = $('select[name="status_filter"] option:selected')[0].value;

Expand Down
87 changes: 49 additions & 38 deletions src/static/js/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,56 +50,67 @@ function getHours() {
}

module.exports = {
stopClock: false,
clockRunning: function() {
if (!this.stopClock) {
var milli = getMilli();
var new_milli = parseInt(milli) - 1;
isStopped: function() {
return getMilli() === '--' &&
getSeconds() === '--' &&
getMinutes() === '--' &&
getHours() === '--';
},
isFinished: function() {
return parseInt(getMilli()) === 0 &&
parseInt(getSeconds()) === 0 &&
parseInt(getMinutes()) === 0 &&
parseInt(getHours()) === 0;
},
runClock: function() {
if (this.isStopped() || this.isFinished()) {
noClock();
return;
}

var milli = getMilli();
var new_milli = parseInt(milli) - 1;

if (new_milli <= 0) {
var seconds = getSeconds();
if (parseInt(seconds) > 0) {
setMilliseconds('99');
if (new_milli <= 0) {
var seconds = getSeconds();
if (parseInt(seconds) > 0) {
setMilliseconds('99');
} else {
setMilliseconds('0');
}
var new_seconds = parseInt(seconds) - 1;
if (new_seconds <= 0) {
var minutes = getMinutes();
if (parseInt(minutes) > 0) {
setSeconds('59');
} else {
setMilliseconds('0');
setSeconds('0');
}
var new_seconds = parseInt(seconds) - 1;
if (new_seconds <= 0) {
var minutes = getMinutes();
if (parseInt(minutes) > 0) {
setSeconds('59');
var new_minutes = parseInt(minutes) - 1;
if (new_minutes <= 0) {
var hours = getHours();
if (parseInt(hours) > 0) {
setMinutes('59');
} else {
setSeconds('0');
setMinutes('0');
}
var new_minutes = parseInt(minutes) - 1;
if (new_minutes <= 0) {
var hours = getHours();
if (parseInt(hours) > 0) {
setMinutes('59');
} else {
setMinutes('0');
}
var new_hours = parseInt(hours) - 1;
if (new_hours <= 0) {
setHours(0);
} else {
setHours(new_hours);
}
var new_hours = parseInt(hours) - 1;
if (new_hours <= 0) {
setHours(0);
} else {
setMinutes(new_minutes);
setHours(new_hours);
}
} else {
setSeconds(new_seconds);
setMinutes(new_minutes);
}
} else {
setMilliseconds(new_milli);
}
if (parseInt(getMilli()) === 0 && parseInt(getSeconds()) === 0 && parseInt(getMinutes()) === 0 && parseInt(getHours()) === 0) {
this.stopClock = true;
noClock();
setSeconds(new_seconds);
}
} else {
clearInterval(this.clockRunning);
setMilliseconds(new_milli);
}

// recurse after 10 ms
setTimeout(this.runClock.bind(this), 10);
}
};
26 changes: 13 additions & 13 deletions src/static/js/fb-ctf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,16 +1344,16 @@ function setupInputListeners() {
* load module generic
*/
function loadModuleGeneric(loadPath, targetSelector) {
$.get(loadPath, function(data) {
var $target = $(targetSelector);
$target.html(data);
var df = $.Deferred();
return df.resolve();
}).error(function() {
console.error("There was a problem retrieving the module.");
console.log(loadPath);
console.error("/error");
});
return $.get(loadPath)
.done(function(data) {
var $target = $(targetSelector);
$target.html(data);
})
.error(function() {
console.error("There was a problem retrieving the module.");
console.log(loadPath);
console.error("/error");
});
}

/**
Expand Down Expand Up @@ -1383,7 +1383,9 @@ function setupInputListeners() {
var clockModulePath = 'inc/gameboard/modules/game-clock.php';
var clockSelector = 'aside[data-module="game-clock"]';

return loadModuleGeneric(clockModulePath, clockSelector);
return loadModuleGeneric(clockModulePath, clockSelector).done(function() {
Clock.runClock();
});
}

/**
Expand Down Expand Up @@ -1760,8 +1762,6 @@ function setupInputListeners() {
Modal.load('p=scoreboard&modal=scoreboard', 'scoreboard');
});

setInterval(Clock.clockRunning, 10);

VIEW_ONLY = $body.data('section') === 'viewer-mode';

if (GAMEBOARD_LOADED === false) {
Expand Down

0 comments on commit 96364c6

Please sign in to comment.