summaryrefslogtreecommitdiff
path: root/src/js/zen.js
blob: e2e7035d90ada95c3795b8adde9e747871e5d1da (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
'use strict';

const articles = document.getElementsByTagName('article');
const header = document.getElementById('side-bar');
const toggleArrow = document.getElementById('harr');

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() {
  if (header && !header.classList.contains('hidden')) {
    header.classList.add('hidden');

    if (articles) {
      [...articles].forEach(e => {
        e.classList.add('zen-mode');
      });
    }
  }
}

function showAbout() {
  if (header && header.classList.contains('hidden')) {
    header.classList.remove('hidden');
    if (articles) {
      [...articles].forEach(e => {
        e.classList.remove('zen-mode');
        e.classList.add('zen-mode-disabling');
      });
      setTimeout(() => {
        [...articles].forEach(e => {
          e.classList.remove('zen-mode-disabling');
        });
      }, 1000);
    }
  }
}

window.addEventListener('scroll', () => {
  const toggleArrow = document.getElementById('harr');

  if (window.pageYOffset >= 800) {
    if (toggleArrow) {
      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');
  }
});