增加比赛倒计时的功能

This commit is contained in:
hohoTT
2015-09-22 12:56:10 +08:00
parent 3b8eef1bab
commit 371b9625c2
12 changed files with 842 additions and 19 deletions

View File

@@ -0,0 +1,40 @@
require(["jquery", "jcountdown"], function($, jcountdown){
function getServerTime(){
var contestId = location.pathname.split("/")[2];
var time = 0;
$.ajax({
url: "/api/contest/time/?contest_id=" + contestId,
dataType: "json",
method: "get",
async: false,
success: function(data){
if(!data.code){
time = data.data;
}
}
});
return time;
}
var time = getServerTime();
if(time["status"] == 1){
countdown(time["start"])
}
else if(time["status"] == 0){
countdown(time["end"])
}
function countdown(t){
$("#timer").countdown({
serverDiff: t,
date: "september 21, 2015 21:59",
yearsAndMonths: false,
template: $('#template').html()
}).on("countComplete", function(){
location.reload();
});
}
});

View File

@@ -142,9 +142,6 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert", "ZeroClipboard"],
if(!data.code){
time = data.data;
}
},
error: function(){
time = new Date().getTime();
}
});
return time;
@@ -153,13 +150,16 @@ require(["jquery", "codeMirror", "csrfToken", "bsAlert", "ZeroClipboard"],
if(location.href.indexOf("contest") > -1) {
setInterval(function () {
var time = getServerTime();
var minutes = parseInt(time / (1000 * 60));
if(minutes == 0){
bsAlert("比赛即将结束");
}
else if(minutes > 0 && minutes <= 5){
bsAlert("比赛还剩" + minutes.toString() + "分钟");
if(time["status"] == 0){
var minutes = parseInt(time["end"] / (1000 * 60));
if(minutes == 0){
bsAlert("比赛即将结束");
}
else if(minutes > 0 && minutes <= 5){
bsAlert("比赛还剩" + minutes.toString() + "分钟");
}
}
}, 1000 * 60);
}