summaryrefslogtreecommitdiff
path: root/src/js/zen.js
blob: be5f7d79a19420e1cf930f3f41ff58fd317b0dd2 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
window.addEventListener('DOMContentLoaded', () => {
  let firstTime = window.location.pathname != '/' && window.pageYOffset < 800;
  const toggleArrow = document.querySelector('#harr');
  const hid = document.querySelector('#hid');
  const initValue = document.body.style.getPropertyValue('--width_panel_bis');

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

      // If the screen is smaller than 500px, hide the HID
      if (window.screen.availWidth <= 500) {
        hideHID();
      }
    }
  });

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

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

  function hideHID() {
    hid.style.setProperty('display', 'none');
  }

  function showHID() {
    hid.style.setProperty('display', '');
  }

  window.addEventListener('scroll', () => {
    if(!toggleArrow) return;
    if (window.pageYOffset >= 800) {
      if (firstTime && document.body.style.getPropertyValue('--width_panel_bis') === initValue) {
        toggleArrow.click();
        firstTime = true;
      }

      toggleArrow.classList.add('hide_arrow_show');
      // A hideAbout(header, articles);
    } else if (!toggleArrow.classList.contains('hide_arrow_off')) {
      // A showAbout(header, articles);
      toggleArrow.classList.remove('hide_arrow_show');
    }

    if(firstTime && window.pageYOffset === 0 && document.body.style.getPropertyValue('--width_panel_bis') !== initValue) {
      toggleArrow.click();
      firstTime = true;
    }
  });
});