notifications.js 887 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const Severity = {
  2. Normal: 1,
  3. Warning: 2,
  4. Critical: 3,
  5. }
  6. function showToast(severity, text) {
  7. var toast = $('#toast');
  8. if (!toast.length) {
  9. $('body').append('<div id="toast" class="toast hidden"></div>');
  10. toast = $('#toast');
  11. }
  12. toast.text(text);
  13. toast.removeClass('normal');
  14. toast.removeClass('warning');
  15. toast.removeClass('critical');
  16. switch(severity) {
  17. case Severity.Warning:
  18. toast.addClass('warning');
  19. break
  20. case Severity.Critical:
  21. toast.addClass('critical');
  22. break
  23. case Severity.Normal:
  24. default:
  25. toast.addClass('normal');
  26. break
  27. }
  28. toast.removeClass('hidden');
  29. toast.addClass('visible');
  30. setTimeout(function() {
  31. toast.removeClass('visible');
  32. toast.addClass('hidden');
  33. }, 2000);
  34. }