Guest User

Untitled

a guest
Feb 11th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. /**
  2. * @file Ações da página 'inicio.html', como abrir e esconder o menu e etc.
  3. * @author Anderson Feitosa
  4. */
  5.  
  6. window.onload = function() {
  7. displayQuantityOfNotReadedNotifications();
  8. };
  9.  
  10. const navOpen = document.getElementById('nav_toggle_open');
  11. const navClose = document.getElementById('nav_toggle_close');
  12. const sidebar = document.getElementById('navbar_left');
  13. const overlay = document.getElementsByClassName('overlay');
  14.  
  15. /**
  16. * Responsável por esconder o menu lateral e a opacidade no fundo e chamar as animações dos mesmos.
  17. */
  18. function hideSideMenu() {
  19. sidebar.classList.add('animate-hide');
  20. overlay[0].style.display = 'none';
  21. setTimeout(function() {
  22. sidebar.classList.remove('animate-hide');
  23. sidebar.style.display = 'none';
  24. }, 400);
  25. }
  26.  
  27. /**
  28. * Responsável por chamar a função que exibe o menu lateral e a opacidade no fundo.
  29. */
  30. navOpen.addEventListener('click', function() {
  31. sidebar.style.display = 'block';
  32. overlay[0].style.display = 'block';
  33. });
  34.  
  35. /**
  36. * Click EventListener que chama a função 'hideSideMenu'.
  37. */
  38. navClose.addEventListener('click', function() {
  39. hideSideMenu();
  40. });
  41.  
  42. /**
  43. * Click EventListener que chama a função 'hideSideMenu'.
  44. */
  45. overlay[0].addEventListener('click', function() {
  46. hideSideMenu();
  47. });
  48.  
  49. /**
  50. * Responsável por verificar no localStorage a quantidade de notificações não lidas.
  51. */
  52. function getQuantityOfNotReadedNotifications() {
  53. const notifications = JSON.parse(localStorage.getItem('notifications')) || [];
  54.  
  55. if (notifications.length !== 0) {
  56. const val = notifications.filter(function(el) {
  57. return el['readed'] === false;
  58. });
  59.  
  60. return val.length;
  61. }
  62.  
  63. return 0;
  64. }
  65.  
  66. /**
  67. * Responsável por chamar a função que exibe o número de notificações não lidas para o usuário.
  68. */
  69. function displayQuantityOfNotReadedNotifications() {
  70. const quantityOfNotifications = getQuantityOfNotReadedNotifications();
  71.  
  72. if (quantityOfNotifications !== 0) {
  73. changeHtmlCounter(quantityOfNotifications);
  74. }
  75. }
  76.  
  77. /**
  78. * Responsável por mudar o HTML do ícone de notificação, mostrando ao usuário que existem notificações não lidas.
  79. * @param {number} quantity - Quantidade das noitificação não lidas que vai se exibida no ícone de notificação.
  80. */
  81. function changeHtmlCounter(quantity) {
  82. const span = document.getElementById('cont-notify');
  83.  
  84. if (span) {
  85. span.innerHTML = quantity;
  86. span.classList.remove('dis-none');
  87. }
  88. }
Add Comment
Please, Sign In to add comment