[FEATURE] Activate timer again
authorFabien Udriot <fabien.udriot@ecodev.ch>
Fri, 25 Apr 2014 10:56:04 +0000 (12:56 +0200)
committerFabien Udriot <fabien.udriot@ecodev.ch>
Fri, 25 Apr 2014 10:56:04 +0000 (12:56 +0200)
Change-Id: Iacd8ea3318209d2e11d86711befaa2890def6cc1

content.html
time.php [new file with mode: 0644]

index 559641a..68ddd25 100644 (file)
@@ -1,3 +1,95 @@
+<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
+
+  <script type="text/javascript">
+
+         // @credit http://stuntsnippets.com/javascript-countdown/
+         var javascript_countdown = function() {
+                 var time_left = 10; //number of seconds for countdown
+                 var output_element_id = 'javascript_countdown_time';
+                 var keep_counting = 1;
+                 var no_time_left_message = 'No time left for JavaScript countdown!';
+
+                 function countdown() {
+                         if (time_left < 2) {
+                                 keep_counting = 0;
+                         }
+
+                         time_left = time_left - 1;
+                 }
+
+                 function add_leading_zero(n) {
+                         if (n.toString().length < 2) {
+                                 return '0' + n;
+                         } else {
+                                 return n;
+                         }
+                 }
+
+                 function format_output() {
+                         var hours, minutes, seconds;
+                         seconds = time_left % 60;
+                         minutes = Math.floor(time_left / 60) % 60;
+                         hours = Math.floor(time_left / 3600);
+
+                         seconds = add_leading_zero(seconds);
+                         minutes = add_leading_zero(minutes);
+                         hours = add_leading_zero(hours);
+
+                         return hours + ':' + minutes + ':' + seconds;
+                 }
+
+                 function show_time_left() {
+                         document.getElementById(output_element_id).innerHTML = format_output();//time_left;
+                 }
+
+                 function no_time_left() {
+                         document.getElementById(output_element_id).innerHTML = no_time_left_message;
+                 }
+
+                 return {
+                         count: function() {
+                                 countdown();
+                                 show_time_left();
+                         },
+                         timer: function() {
+                                 javascript_countdown.count();
+
+                                 if (keep_counting) {
+                                         setTimeout("javascript_countdown.timer();", 1000);
+                                 } else {
+                                         no_time_left();
+                                 }
+                         },
+                         //Kristian Messer requested recalculation of time that is left
+                         setTimeLeft: function(t) {
+                                 time_left = t;
+                                 if (keep_counting == 0) {
+                                         javascript_countdown.timer();
+                                 }
+                         },
+                         init: function(t, element_id) {
+                                 time_left = t;
+                                 output_element_id = element_id;
+                                 javascript_countdown.timer();
+                         }
+                 };
+         }();
+
+         // json-time.appspot.com is sometimes over-quota... use a home made solution
+         $.get("/time.php", function(time) {
+                 var now = new Date(time);
+                 var hourInterval = 1
+                 var hour = (now.getHours() + 1) % hourInterval;
+                 var minute = now.getMinutes();
+                 var second = now.getSeconds();
+                 var timeSpent = hour * 3600 + minute * 60 + second;
+                 var timeLeft = (hourInterval * 3600) - timeSpent;
+
+                 //time to countdown in seconds
+                 javascript_countdown.init(timeLeft, 'javascript_countdown_time');
+         });
+  </script>
+
 <ul class="breadcrumbs">
        <li>
                <a href="http://typo3.org/" target="_top" title="TYPO3 - The Enterprise Open Source CMS">typo3.org</a>
        are enabled such as file upload, third-party extension installation, etc... for obvious security reasons</strong>.
 </p>
 <p>
-       Each packages are reset after a certain amount of time, so don't hesitate to experiment as much as you like but please let
-       the system still usable for the next one. Next reset will happen in <strong id="javascript_countdown_time"></strong>.
+       Don't hesitate to experiment as much as you like but please let the system still usable for the next visitor.
+       <br>
+       Next reset will happen in <strong id="javascript_countdown_time"></strong>.
 </p>
 <a id="c3084"></a>
 
diff --git a/time.php b/time.php
new file mode 100644 (file)
index 0000000..9a2b57a
--- /dev/null
+++ b/time.php
@@ -0,0 +1,5 @@
+<?php
+
+header('Access-Control-Allow-Origin: *');
+date_default_timezone_set("UTC");
+echo date("c");
\ No newline at end of file