]> git.parisson.com Git - teleforma.git/commitdiff
Fix timing issue with last versions of Chrome : https://trackers.pilotsystems.net...
authorYoan Le Clanche <yoanl@pilotsystems.net>
Tue, 19 May 2020 09:40:57 +0000 (11:40 +0200)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Tue, 19 May 2020 09:40:57 +0000 (11:40 +0200)
teleforma/static/teleforma/js/application.js
teleforma/templates/teleforma/seminar_detail.html

index c5f744bca57f56caf8707bd350a0b07511ae0f47..150f8f403a4d7df9bb926daeded3cee11e65cbf2 100644 (file)
@@ -31,34 +31,49 @@ rainbow.setSpectrum('#bb0000', '#e65911', '#f3ad17', 'green');
 
 
 function pad(num) {
-    var s = num+"";
-    while (s.length < 2) s = "0" + s;
-    return s;
+        var s = num + "";
+        while (s.length < 2) s = "0" + s;
+        return s;
 }
 
-$(window).ready(function() {
-       var pageHeight = $(window).height();
-       var navHeight = pageHeight - 125;
-       $('#desk_center').css({"max-height": navHeight + 'px'});
+$(window).ready(function () {
+        var pageHeight = $(window).height();
+        var navHeight = pageHeight - 125;
+        $('#desk_center').css({ "max-height": navHeight + 'px' });
         launchTimer();
 });
 
 
-var launchTimer = function(){
+var launchTimer = function () {
         // chronometer
-        $('.autotimer').each(function(){
+        $('.autotimer').each(function () {
                 window.timer = new Timer();
                 $timerSpan = $(this);
                 var value = $timerSpan.text()
                 // convert text value of timer to seconds
                 var timeArray = value.split(':');
                 var seconds = parseInt(timeArray[0], 10) * 3600 + parseInt(timeArray[1], 10) * 60 + parseInt(timeArray[2], 10);
-                window.timer.start({precision: 'seconds', startValues: {seconds: seconds}}); 
+                window.timer.start({ precision: 'seconds', startValues: { seconds: seconds } });
                 window.timer.addEventListener('secondsUpdated', function (e) {
-                    var timeValues = window.timer.getTimeValues();
-                    var hours = timeValues.days * 24 + timeValues.hours
-                    $timerSpan.html(pad(hours) + ':' + pad(timeValues.minutes) + ':' + pad(timeValues.seconds));
+                        var timeValues = window.timer.getTimeValues();
+                        var hours = timeValues.days * 24 + timeValues.hours
+                        $timerSpan.html(pad(hours) + ':' + pad(timeValues.minutes) + ':' + pad(timeValues.seconds));
                 });
         });
 }
 
+function onLoadSeminar(seminarId, username) {
+        // send a request when user load a seminar
+        json([seminarId, username], 'teleforma.seminar_load', function () { return null; });
+}
+
+function onUnloadSeminar(seminarId, username) {
+        try {
+                var params = JSON.stringify({ "id": "jsonrpc", "params": [seminarId, username], "method": "teleforma.seminar_unload", "jsonrpc": "1.0" })
+                navigator.sendBeacon("json/", params);
+        }
+        catch {
+                // compatibility with old navigators
+                json_sync([seminarId, username], 'teleforma.seminar_unload', function () { return null; });
+        }
+}
index b35cb683af144648f8851bd9461eba7b5ef8ddb9..0887a062151c3c2da419802a2abb6317645fe921 100644 (file)
@@ -67,9 +67,10 @@ var seminarUtils = {
 
 var f = seminarUtils;
 
-$(document).ready(function( ){
-      f.load('{{seminar.id}}','{{user.username}}');
-    });
+var f = seminarUtils;
+$(document).ready(function(){
+    onLoadSeminar('{{seminar.id}}','{{user.username}}')
+});
 
 $(window).ready(function( ){
   {% if user.is_staff %}
@@ -85,10 +86,10 @@ $(window).ready(function( ){
             }
         });
   {% endif %}
-      $(window).bind('beforeunload', function(){
-            f.unload('{{seminar.id}}','{{user.username}}');
-          });
+    $(window).bind('beforeunload', function(){
+        onUnloadSeminar('{{seminar.id}}','{{user.username}}')        
     });
+});
 
 </script>