summaryrefslogtreecommitdiff
path: root/src/js/zen.js
blob: 301e21b286d2bbd2f568d3e9209069eb4c12378e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
window.addEventListener('DOMContentLoaded', () => {
  let firstTime = window.location.pathname != '/';
  const toggleArrow = document.querySelector('#harr');
  const initValue = document.body.style.getPropertyValue('--width_panel_bis');

  toggleArrow.addEventListener('click', () => {
    if (toggleArrow.classList.contains('hide_arrow_off')) {
      showAbout();
      setTimeout(() => {
        toggleArrow.classList.remove('hide_arrow_off');
      }, 1000);
    } else {
      toggleArrow.classList.add('hide_arrow_off');
      hideAbout();
    }
  });

  function hideAbout() {
    document.body.style.setProperty('--width_panel_bis', '0px');
  }

  function showAbout() {
    document.body.style.setProperty('--width_panel_bis', initValue);
  }

  window.addEventListener('scroll', () => {
    if (window.pageYOffset >= 800) {
      if (toggleArrow) {
        if (firstTime) {
          toggleArrow.click();
          firstTime = false;
        } else {
          toggleArrow.classList.add('hide_arrow_show');
        }
      }
      // A hideAbout(header, articles);
    } else if (toggleArrow && !toggleArrow.classList.contains('hide_arrow_off')) {
      // A showAbout(header, articles);
      toggleArrow.classList.remove('hide_arrow_show');
    }
  });
});