Source: js/app.js

/**
 * @author    Wolfgang Kowarschick <kowa@hs-augsburg.de>
 * @copyright 2017
 * @license   CC-BY-NC-SA-4.0
 */

import '../css/app.scss';
import '../json/init.js';
import * as init_de from '../json/init_de.json';
import * as init_en from '../json/init_en.json';
import Greet        from './app/greet.js';

/**
 * Initializes the HTML sections of the app that are
 * stated in <code>p_init</code>.
 *
 * @param p_window {Object}
 *          The browser window that contains the HTML document
 *          to be initialized.
 * @param p_init {JSONinit}
 *          The initialization info for the form and the
 *          welcome section.
 */
function init(p_window, p_init)
{
  const l_document      = p_window.document,
        l_init_elements = p_init.HTMLElements,
        l_init_text     = p_init.text,
        l_greet         = new Greet(l_document, p_init);

  l_document.getElementById(l_init_elements.div).lang
    = l_init_elements.lang;
  l_document.getElementById(l_init_elements.headingForm).innerHTML
    = l_init_text.title;
  l_document.getElementById(l_init_elements.inputNameLabel).innerHTML
    = l_init_text.query;
  l_document.getElementById(l_init_elements.buttonReset).value
    = l_init_text.reset;
  l_document.getElementById(l_init_elements.buttonSubmit).value
    = l_init_text.submit;
  l_document.getElementById(l_init_elements.buttonSubmit)
            .addEventListener('click', l_greet.sayHello);
  p_window.addEventListener('keydown', l_greet.sayHelloOnEnter);

  // As the form has been initialized completely,
  // make it visible.
  l_document.getElementById(l_init_elements.sectionForm)
            .classList.remove('hidden');
}

// Initialize the app.
init(window, init_de);
init(window, init_en);