diff util.js @ 19:bde4f0bbfe69

Clear a spinner’s timeout on change if it had been set previously.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 22 Dec 2018 19:53:01 +0100
parents 07543f7f5e89
children 6c620e9f7d2c
line wrap: on
line diff
--- a/util.js
+++ b/util.js
@@ -44,23 +44,31 @@ function configurePEPField(node, key, va
 }
 
 function displaySpinner(spinner) {
+    if ('timeoutid' in spinner.dataset)
+        clearTimeout(spinner.dataset.timeoutid);
     spinner.src = 'spinner.svg';
     spinner.hidden = false;
 }
 
 function spinnerOk(spinner) {
+    if ('timeoutid' in spinner.dataset)
+        clearTimeout(spinner.dataset.timeoutid);
     spinner.src = 'ok.svg';
     spinner.hidden = false;
-    setTimeout(function () {
+    spinner.dataset.timeoutid = setTimeout(function () {
         spinner.hidden = true;
     }, 1000);
 }
 
 function spinnerError(spinner) {
+    if ('timeoutid' in spinner.dataset)
+        clearTimeout(spinner.dataset.timeoutid);
     spinner.src = 'error.svg';
     spinner.hidden = false;
 }
 
 function hideSpinner(spinner) {
+    if ('timeoutid' in spinner.dataset)
+        clearTimeout(spinner.dataset.timeoutid);
     spinner.hidden = true;
 }