From 88d7b770a545f4e5159e22351f3fb4057795d47b Mon Sep 17 00:00:00 2001 From: Yoan Le Clanche Date: Tue, 19 May 2020 11:40:57 +0200 Subject: [PATCH] Fix timing issue with last versions of Chrome : https://trackers.pilotsystems.net/probarreau/0717 --- teleforma/static/teleforma/js/application.js | 41 +++++++++++++------ .../templates/teleforma/seminar_detail.html | 13 +++--- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/teleforma/static/teleforma/js/application.js b/teleforma/static/teleforma/js/application.js index c5f744bc..150f8f40 100644 --- a/teleforma/static/teleforma/js/application.js +++ b/teleforma/static/teleforma/js/application.js @@ -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; }); + } +} diff --git a/teleforma/templates/teleforma/seminar_detail.html b/teleforma/templates/teleforma/seminar_detail.html index b35cb683..0887a062 100644 --- a/teleforma/templates/teleforma/seminar_detail.html +++ b/teleforma/templates/teleforma/seminar_detail.html @@ -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}}') }); +}); -- 2.39.5