2019-09-30 23:05:06 +02:00
|
|
|
application.togglePrettierEnabled()// client-side js
|
2018-03-13 21:25:39 +01:00
|
|
|
// run by the browser each time your view template is loaded
|
|
|
|
|
2019-09-30 23:05:06 +02:00
|
|
|
console.log("hello world :o");
|
2018-06-25 20:47:57 +02:00
|
|
|
|
|
|
|
// our default array of dreams
|
|
|
|
const dreams = [
|
2019-09-30 23:05:06 +02:00
|
|
|
"Find and count some sheep",
|
|
|
|
"Climb a really tall mountain",
|
|
|
|
"Wash the dishes"
|
2018-06-25 20:47:57 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
// define variables that reference elements on our page
|
2019-09-30 23:05:06 +02:00
|
|
|
const dreamsList = document.getElementById("dreams");
|
2018-06-25 20:47:57 +02:00
|
|
|
const dreamsForm = document.forms[0];
|
2019-09-30 23:05:06 +02:00
|
|
|
const dreamInput = dreamsForm.elements["dream"];
|
2018-06-25 20:47:57 +02:00
|
|
|
|
|
|
|
// a helper function that creates a list item for a given dream
|
|
|
|
const appendNewDream = function(dream) {
|
2019-09-30 23:05:06 +02:00
|
|
|
const newListItem = document.createElement("li");
|
2018-06-25 20:47:57 +02:00
|
|
|
newListItem.innerHTML = dream;
|
|
|
|
dreamsList.appendChild(newListItem);
|
2019-09-30 23:05:06 +02:00
|
|
|
};
|
2018-06-25 20:47:57 +02:00
|
|
|
|
|
|
|
// iterate through every dream and add it to our page
|
2019-09-30 23:05:06 +02:00
|
|
|
dreams.forEach(function(dream) {
|
2018-06-25 20:47:57 +02:00
|
|
|
appendNewDream(dream);
|
|
|
|
});
|
|
|
|
|
|
|
|
// listen for the form to be submitted and add a new dream when it is
|
|
|
|
dreamsForm.onsubmit = function(event) {
|
|
|
|
// stop our form submission from refreshing the page
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
// get dream value and add it to the list
|
|
|
|
dreams.push(dreamInput.value);
|
|
|
|
appendNewDream(dreamInput.value);
|
|
|
|
|
2019-09-30 23:05:06 +02:00
|
|
|
// reset form
|
|
|
|
dreamInput.value = "";
|
2018-06-25 20:47:57 +02:00
|
|
|
dreamInput.focus();
|
|
|
|
};
|