Advertisement
mark79

Notification

Dec 12th, 2020 (edited)
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const elements = {
  2.     infoBox: document.querySelector('.notification.infoBox'),
  3.     loadingBox: document.querySelector('.notification.loadingBox'),
  4.     errorBox: document.querySelector('.notification.errorBox'),
  5. }
  6.  
  7. elements.infoBox.addEventListener('click', hideInfo);
  8. elements.errorBox.addEventListener('click', hideError);
  9.  
  10. function showError(msg) {
  11.     if (msg.hasOwnProperty('message')) {
  12.         msg = msg.message;
  13.     }
  14.     elements.errorBox.textContent = msg;
  15.     elements.errorBox.style.display = 'block';
  16.     setTimeout(hideError, 3000);
  17. }
  18.  
  19. function showInfo(msg) {
  20.     if (msg.hasOwnProperty('message')) {
  21.         msg = msg.message;
  22.     }
  23.     elements.infoBox.textContent = msg;
  24.     elements.infoBox.style.display = 'block';
  25.     setTimeout(hideInfo, 3000);
  26. }
  27.  
  28. function showLoading() {
  29.     elements.loadingBox.textContent = 'Loading …';
  30.     elements.loadingBox.style.display = 'block';
  31. }
  32.  
  33. function hideLoading() {
  34.     elements.loadingBox.style.display = 'none';
  35. }
  36.  
  37. function hideError() {
  38.     elements.errorBox.style.display = 'none';
  39. }
  40.  
  41. function hideInfo() {
  42.     elements.infoBox.style.display = 'none';
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement