tagliatelle

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

common.js (788B)


      1 function escapeHtml(text) {
      2     const div = document.createElement('div');
      3     div.textContent = text;
      4     return div.innerHTML;
      5 }
      6 
      7 // Appends a hidden input to a form
      8 function appendHidden(form, name, value) {
      9     const input = document.createElement('input');
     10     input.type = 'hidden';
     11     input.name = name;
     12     input.value = value;
     13     input.dataset.generated = '1';
     14     form.appendChild(input);
     15 }
     16 
     17 // Fades out and removes elements matching selector
     18 function autoHideSuccessMessages(selector = '.auto-hide-success', delay = 5000) {
     19     document.querySelectorAll(selector).forEach(div => {
     20         setTimeout(() => {
     21             div.style.transition = 'opacity 0.5s';
     22             div.style.opacity = '0';
     23             setTimeout(() => div.remove(), 500);
     24         }, delay);
     25     });
     26 }