File size: 1,171 Bytes
bd98362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
var flight = require('flightjs');
var template = require('./templates/title.hogan');

const TYPING_DELAY = 42;
const BASE_TYPING_DELAY = 50;

function helloWorldUI() {

  this.attributes({

  });

  this.typewriter = function(str) {
    var instance = this;
    var textEl = document.querySelector('[data-text]');
    var arr = str.split('');
    var i = 0;
    textEl.innerHTML = '';

    setTimeout(function() {
      instance.setText(textEl, arr, 0);
    }, BASE_TYPING_DELAY);
  };

  this.setText = function(el, arr, i) {
    var instance = this;
    var delay = (TYPING_DELAY * Math.random()) + BASE_TYPING_DELAY;
    if (arr[i]) {
      el.innerHTML += arr[i];
      i++;
      setTimeout(function() {
        instance.setText(el, arr, i);
      }, delay);
    }
  };

  this.render = function(name) {
    var titleEl = document.querySelector('[data-title]');

    titleEl.innerHTML = template.render({
      name: name
    });
  }

  this.after('initialize', function() {
    this.render('Hanna');
    this.typewriter.call(this, 'Welcome to the Epsilon Eridani system. What would you like to do next?');
  });

}

module.exports = flight.component(helloWorldUI);