Compare commits

...

8 commits

Author SHA1 Message Date
Augusto Dwenger e272b77b50
Create README.md 2019-05-31 13:15:54 +02:00
hamburghammer a3a655a15a refactoring: unused functions removed or commented out and added
comments for better understanding
2019-02-25 22:01:08 +01:00
hamburghammer 8e6a2af136 Merge branch 'dev'
neu benamung der html
2018-11-13 15:27:32 +01:00
hamburghammer a12ec7d19d Standard.html renamed to index.html 2018-11-13 15:26:56 +01:00
hamburghammer 647b5d1f24 returns vereinfacht 2018-10-04 15:09:59 +02:00
hamburghammer a9e0edab55 v2.0.0 2018-10-03 20:58:43 +02:00
hamburghammer 4171920a23 fix completed aus dem Storage korrekt anzuzeigen 2018-10-02 17:07:13 +02:00
hamburghammer 9c6851a2f3 Fixed render on load 2018-10-02 16:20:00 +02:00
4 changed files with 31 additions and 33 deletions

9
README.md Normal file
View file

@ -0,0 +1,9 @@
# todoApp
JavaScript To-Do Web-App
It is my firs JS App. The whole purpose was to get use and learn the basics.
The App is written in vanilla JavaScript and bearly styled.
Through and input field you can add to-do's to the list. In the list you can check and uncheck as well delete the to-do's.
Special thanks to [MOINWORLD e.V.](https://moinworld.de/en/)

View file

@ -1,6 +1,6 @@
{
"name": "todoapp",
"version": "1.1.0",
"version": "2.0.0",
"description": "",
"main": "todoApp.js",
"scripts": {

View file

@ -4,12 +4,13 @@ var todoList = [],
i = 0,
storedTodoList,
text;
const todoListDiv = document.getElementById("Todos");
if (typeof localStorage === "undefined" || localStorage === null) {
var LocalStorage = require('node-localstorage').LocalStorage;
localStorage = new LocalStorage('./scratch');
}
// if (typeof localStorage === "undefined" || localStorage === null) {
// var LocalStorage = require('node-localstorage').LocalStorage;
// localStorage = new LocalStorage('./scratch');
// }
function checkForStorage(){
@ -33,6 +34,7 @@ function addEntry(event) {
const myInput = document.getElementById("myInput");
text = myInput.value;
//checking the submited text
if (text === "" || typeof text === 'undefined' || text === null ) {
return alert("Bitte gib Text ein!");
}
@ -45,23 +47,19 @@ function addEntry(event) {
return alert("Du hast schon so ein To-Do!")
}
//adding the text to the local list and into the storage
addTodoToList(text);
setLocalStorage(todoList);
let lastTodo = todoList.length -1;
const todoEntryDiv = createTodoEntry(lastTodo);
todoListDiv.appendChild(todoEntryDiv);
createTodoEntry(lastTodo);
myInput.value = "";
myInput.focus();
}
//Main function <---
//creating the entry / element inside the HTML
function createTodoEntry(todoEntry) {
todoEntryDiv = document.createElement("div");
@ -71,19 +69,18 @@ function createTodoEntry(todoEntry) {
let checkbox = document.createElement("input");
checkbox.setAttribute('type', 'checkbox');
checkbox.checked = todoList[todoEntry].completed;
if (checkbox.checked === true){
let doneTodoList = document.getElementById("doneTodos");
doneTodoList.appendChild(todoEntryDiv)
}
checkbox.addEventListener('change', function(){
if (checkbox.checked === true){
let doneTodoList = document.getElementById("doneTodos");
doneTodoList.appendChild(document.getElementById(todoEntry));
todoList[todoEntry].completed = true;
setLocalStorage(todoList);
}else {
todoListDiv.appendChild(document.getElementById(todoEntry));
todoList[todoEntry].completed = false;
setLocalStorage(todoList);
}
})
@ -109,8 +106,13 @@ function createTodoEntry(todoEntry) {
setLocalStorage(todoList);
location.reload(true);
}
console.log("Done!");
return todoEntryDiv;
if (checkbox.checked === true){
let doneTodoList = document.getElementById("doneTodos");
return doneTodoList.appendChild(todoEntryDiv);
}
return todoListDiv.appendChild(todoEntryDiv);
}
function setLocalStorage(storeData) {
@ -118,11 +120,10 @@ function setLocalStorage(storeData) {
}
function getLocalStorage() {
storedTodoList = JSON.parse(localStorage.getItem("savedTodoList"));
return storedTodoList;
return JSON.parse(localStorage.getItem("savedTodoList"));
}
//TodoList object
function addTodoToList(todo) {
todoList.push({
completed: false,
@ -130,18 +131,6 @@ function addTodoToList(todo) {
})
}
function setTodoList(todoList) {
todoList = todoList;
}
function getTodoList() {
return todoList;
}
function foo(bar) {
return bar;
}
function rmTodo(position) {
todoList.splice(position, 1);
}