aboutsummaryrefslogtreecommitdiff
path: root/header.sh
blob: 2e9f467c6e543e6eef1412ebc61f164728e9053f (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash

cat <<HEADER
<style>
  header h1, header h2 {
    text-align: left;
    line-break: anywhere;
  }

  header .separator-wrap {
    margin-top: 15px;
  }

  .cursor {
    background-color: var(--primary-fg);
    animation-name: blink-animation;
    animation-duration: 500ms;
    animation-iteration-count: infinite;
    animation-timing-function: cubic-bezier(0.83,-0.22, 0.54, 0.55);
  }

  @keyframes blink-animation {
    to {
      opacity: 0;
    }
  }

  .mobile { display: none; }

  @media screen and (max-width: 769px) {
    .mobile { display: block; }
    .desktop { display: none; }
  }
</style>

<script type="text/javascript">
  let mobileText = '$HEADER_TITLE_MOBILE';
  let desktopText = '$HEADER_TITLE';
  let isMobile = window.innerWidth < 769;

  function hideContent() {
    let mainContainer = document.querySelector('main');
    let footer = document.querySelector('footer');
    let headerSeparator = document.querySelector('header > .separator-wrap');
    mainContainer.style.opacity = '0';
    footer.style.opacity = '0';
    headerSeparator.style.opacity = '0';
  }

  function showContent() {
    let mainContainer = document.querySelector('main');
    let footer = document.querySelector('footer');
    let headerSeparator = document.querySelector('header > .separator-wrap');
    mainContainer.style.transition = '500ms';
    mainContainer.style.opacity = '1';
    footer.style.transition = '500ms';
    footer.style.opacity = '1';
    headerSeparator.style.transition = '500ms';
    headerSeparator.style.opacity = '1';

  }

  function typingAnimation(el, text, index, cb) {
    let char = text[index];
    if (char == ';') {
      el.innerHTML += '<br />';
    } else if (char == ' ') {
      el.innerHTML += '&ensp;';
    } else {
      el.innerText += char;
    }
    
    if (index < text.length - 1) {
      setTimeout(() => typingAnimation(el, text, index + 1, cb), 30);
    } else {
      cb();
    }
  }

  document.addEventListener('DOMContentLoaded', function(event) {
    hideContent();
    let titleMobile = document.querySelector("#header-title-mobile > .text");
    let titleDesktop = document.querySelector('#header-title > .text');

    if (isMobile) {
      titleMobile.innerHTML = '';
    } else {
      titleDesktop.innerHTML = '';
    }

    setTimeout(() => {
      if (isMobile) {
        typingAnimation(titleMobile, mobileText, 0, showContent);
      } else {
        typingAnimation(titleDesktop, desktopText, 0, showContent);
      }
    }, 200);
  });
</script>

<header>
  <h1 id="header-title" class="desktop">$ <span class="text">echo "Jefferson Julio" >> ./programadores</span><span class="cursor">&ensp;</span></h1>
  <h1 id="header-title-mobile" class="mobile">$ <span class="text">echo "Jefferson Julio" \\<br/> >> ./programadores</span><span class="cursor">&ensp;</span></h1>
  <div class="separator-wrap"><div class="separator"></div></div>
</header>
HEADER