summaryrefslogtreecommitdiffhomepage
path: root/assets/js/process.js
blob: 988d9bf290d1796099638b44bab701c39e3e46cc (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 * Fill the diagram with 1s and 0s (animated)
 */
document.getElementById('fill').onclick = () => {
  document.getElementById('combine').style.display = 'block';
  const elements = document.getElementsByClassName('output');

  // reset diagram
  for (let i = 0; i < elements.length; i++) {
    document.getElementById(i + 1).innerText = '';
  }

  // fill diagram
  for (let i = 0; i < elements.length; i++) {
    ((ind) => { // awesome animation
      setTimeout(() => {
        document.getElementById(i + 1).innerText = elements[i].classList.contains('true') ? '1' : '0';
      }, 150 * ind)
    })(i)
  }
};

/**
 * Combining fields to blocks (animated)
 */
document.getElementById('combine').onclick = () => {
  document.getElementById('fill').style.display = 'none';
  document.getElementById('combine').innerText = 'Weiter';
  const steps = document.getElementById('steps');
  const elements = document.getElementsByClassName('grid-child');

  // mark truthy values
  steps.insertAdjacentHTML('beforeend', '<li>Finden von wahren Werten (grün markiert)</li>');
  for (let i = 0; i < elements.length; i++) {
    if (elements[i].getAttribute('id') !== null && elements[i].innerText === '1') {
      elements[i].style.background = 'lightgreen'
    }
  }

  // combine fields - stage 1
  document.getElementById('combine').onclick = () => {
    steps.insertAdjacentHTML('beforeend', '<li>Felder zu Blöcken zusammenfassen <ul id="field_dnf"></ul></li>');
    const fieldDnf = document.getElementById('field_dnf');

    // reset field color
    for (let i = 0; i < elements.length; i++) {
      elements[i].style.background = 'white'
    }

    document.getElementById('3').style.background = 'green';
    document.getElementById('4').style.background = 'green';
    document.getElementById('11').style.background = 'green';
    document.getElementById('12').style.background = 'green';

    fieldDnf.insertAdjacentHTML('beforeend', '<li data-contrast style="color: green">(E<sub>2</sub>&and;<span class="not">E<sub>3</sub></span>)</li>');

    // combine fields - stage 2
    document.getElementById('combine').onclick = () => {
      document.getElementById('11').style.background = 'linear-gradient(to top right, blue, green)';
      document.getElementById('15').style.background = 'blue';

      fieldDnf.insertAdjacentHTML('beforeend', '<li data-contrast style="color: blue">(<span class="not">E<sub>1</sub></span>&and;E<sub>2</sub>&and;E<sub>4</sub>)</li>');

      // combine fields - stage 3
      document.getElementById('combine').onclick = () => {
        document.getElementById('6').style.background = 'orange';

        fieldDnf.insertAdjacentHTML('beforeend',
          '<li data-contrast style="color: orange">(E<sub>1</sub>&and;<span class="not">E<sub>2</sub></span>&and;E<sub>3</sub><span class="not">E<sub>4</sub></span>)</li>');

        document.getElementById('combine').style.display = "none";
      }
    };
  };
};

/**
 * Scroll up magic
 */
const button = document.getElementById('up');
const options = {top: 0, left: 0, behavior: 'smooth'};
button.addEventListener('click', () => {
  window.scroll(options)
});