diff options
| author | Savetheinternet <savetheinternet@n0v4.com> | 2011-01-03 15:00:14 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@n0v4.com> | 2011-01-03 15:00:14 +1100 |
| commit | 98c62258b46a40bfc1669987f227c677b9942e3d (patch) | |
| tree | c0a88655dfd15cd0cc36a1c5713ee7eefa5da99e /inc/functions.php | |
| parent | a0ae475ea450b6cacdb615698d8bfc62d0c99540 (diff) | |
Improved countdown timer
Diffstat (limited to 'inc/functions.php')
| -rw-r--r-- | inc/functions.php | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/inc/functions.php b/inc/functions.php index b56bf29d..de188f0b 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -97,22 +97,27 @@ : '') . '<p>Your ban was filed on <strong>' . formatDate($ban['set']) . - '</strong>, and ' . + '</strong>, and <span id="expires">' . ($ban['expires'] ? - 'expires <span id="until">' . until($ban['expires']) . '</span> from now, which is on <strong><span id="enddate">' . + 'expires <span id="countdown">' . until($ban['expires']) . '</span> from now, which is on <strong>' . formatDate($ban['expires']) . - '</span></strong> + '</strong> <script> // return date("jS F, Y", $timestamp); var secondsLeft = ' . ($ban['expires'] - time()) . ' var end = new Date().getTime() + secondsLeft*1000; function updateExpiresTime() { - document.getElementById("until").innerHTML = until(end); + countdown.firstChild.nodeValue = until(end); } function until(end) { var now = new Date().getTime(); var diff = Math.round((end - now) / 1000); // in seconds - if (diff < 60) { + if (diff < 0) { + document.getElementById("expires").innerHTML = "has since expired. Refresh the page to continue."; + //location.reload(true); + clearInterval(int); + return ""; + } else if (diff < 60) { return diff + " second" + (diff == 1 ? "" : "s"); } else if (diff < 60*60) { return (num = Math.round(diff/(60))) + " minute" + (num == 1 ? "" : "s"); @@ -126,11 +131,13 @@ return (num = Math.round(diff/(60*60*365))) + " year" + (num == 1 ? "" : "s"); } } + var countdown = document.getElementById("countdown"); + updateExpiresTime(); - setInterval(updateExpiresTime, 1000); + var int = setInterval(updateExpiresTime, 1000); </script>' - : '<em>will not expire</em>' ) . - '</p> + : '<em>will not expire</em>.' ) . + '</span></p> <p>Your IP address is <strong>' . $_SERVER['REMOTE_ADDR'] . '</strong>.</p> </div>'; |
