Suite du sujet Plugin Compte à rebours :
Salut, je fais suite a ce sujet car j’utilise cette technique pour lancer un compte a rebours de 60 secondes sur mon design après l’alarme activée. Ca fonctionne néanmoins j’ai des erreurs javascript qui en ressortent. les voici:
http://192.168.1.62/index.php?v=d&p=plan&plan_id=28 line 2 > injectedScript 45 TypeError: event is undefined
la ligne en question
Et voici le code du widget
<!-- WIDGET SPECIFIQUE widget "tps_restant"
Modifications :
- update, _options.display_value, et stop fonction
Mise à jour :
- Le 2019/4/16 : conforme jeedom v3.3.20
Modification :
<span style="font-weight: bold; font-size: 12px;" class="cmdName">#name_display#</span><br/>
-->
<div style="min-width:90px; min-height:62px; margin-right:5px; margin-left:5px; padding:0px !important;" class="tooltips cmd cmd-widget" data-type="info" data-subtype="numeric" data-cmd_id="#id#" title="Valeur du #valueDate#, collectée le #collectDate#">
<center>
<span style="font-weight: bold; font-size: 12px;" class="cmdName"></span><br/>
<span style="font-size: 3em; font-weight: bold;" id="countdown_#id#_decompte"></span>
</center>
<script>
jeedom.cmd.update['#id#'] = function(_options){
var timestamp = parseFloat(_options.display_value);
$(function (e) {
if (timestamp > 0) {
interval#id# = setInterval(function () {
var now = (new Date()).getTime(); // On déclare la date d'aujourd'hui.
var tps_restant =timestamp*1000 - now; // Temps restant en millisecondes
// console.log("interval("+intervalId+")");
if (!$('#countdown_#id#_decompte').length || timestamp < 0 || tps_restant < 0) {
// console.log("clearInterval("+intervalId+")");
clearInterval(interval#id#);
$('#countdown_#id#_decompte').text(' ');
} else {
//============ CONVERSIONS
var s_restantes = tps_restant / 1000; // Secondes restantes
var i_restantes = s_restantes / 60; // Minutes restantes
var H_restantes = i_restantes / 60; // Heures restantes
s_restantes = Math.floor(s_restantes % 60); // Secondes restantes
i_restantes = Math.floor(i_restantes % 60); // Minutes restantes
H_restantes = Math.floor(H_restantes); // Heures restantes
//==================
//============ FORMATTAGE
s_restantes = s_restantes < 10 ? "0"+ s_restantes : s_restantes;
i_restantes = i_restantes < 10 ? "0"+ i_restantes : i_restantes;
H_restantes = H_restantes < 10 ? "0"+ H_restantes : H_restantes;
//==================
if (H_restantes > 0) {
$('#countdown_#id#_decompte').text(H_restantes + ":" + i_restantes + ":" +s_restantes);
} else {
$('#countdown_#id#_decompte').text(i_restantes + ":" +s_restantes);
}
}
}, 1000);
}else {
clearInterval(interval#id#);
$('#countdown_#id#_decompte').text(' ');
e.stopPropagation();
}
});
}
jeedom.cmd.update['#id#']({display_value:'#state#',valueDate:'#valueDate#',collectDate:'#collectDate#',alertLevel:'#alertLevel#'});
</script>
</div>