-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·37 lines (31 loc) · 1.99 KB
/
main.js
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
let outputHtmlObject; //HTML object that will be used to display tools
let unitConvertButton, mortgageButton, currencyButton, mainPageButton; //HTML button objects
let mainPageContent; //Object used to store content for the main page
//Function called when app loaded for the first time, to initialize all variables and add event listeners to all html objects
const initialize = () => {
//Initialize all html objects that will be used in the application
outputHtmlObject = document.getElementById("output");
mainPageButton = document.getElementById("mainPageButton");
unitConvertButton = document.getElementById("unitConvertButton");
mortgageButton = document.getElementById("mortgageButton");
currencyButton = document.getElementById("currencyButton");
//Add event listeners to all html objects
mainPageButton.addEventListener("click", renderMainPage, false);
unitConvertButton.addEventListener("click", unitConversion, false);
unitConvertButton.addEventListener("click", unitConversion, false);
mortgageButton.addEventListener("click", mortgageCalculator, false);
currencyButton.addEventListener("click", currencyConverter, false);
//Render main page when app is loaded for the first time
renderMainPage();
};
//Function rendering main page content
const renderMainPage = () => {
if (mainPageContent === undefined) {
mainPageContent = "<div class='container'><p class='description'>" +
"The app consists of three tools: <i>Unit Converter</i>, <i>Morgtgage Calculator</i> and <i>Currency converter</i>. <br /> Please note that you will need an access to the Internet to use" +
" the Currency converter, because the exchange rates are fetched from a publicly available API. This app is created with vanilla JavaScript and JQuery</p></div>";
}
outputHtmlObject.innerHTML = mainPageContent;
};
//Add load event listener to window object
window.addEventListener("load", initialize, false);