Skip to content

Improved Index page #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@
In this tutorial, a JavaScript beginner can be able to create a beautiful and functional to do list using JavaScript.
I will talk about the logic behind every line of code, before opening my text editor and start typing the code.
it's a step by step tutorial, you won't get lost at any stage of this tutorial.

to follow the tutorial step by step, when we get to the second part (when we type the code), you'll need to download the starter template from here.

The tutorial video link : https://youtu.be/b8sUhU_eq3g

When you open the folder, you'll find all the files needed to get started, the CSS code, is already typed (see style.css file), as we're not going to talk about CSS in our tutorial. we're going just to talk about HTML and JavaScript.

the to-do list we're going to create has a beautiful UI, the user can add a to-do by filling the input and hit ENTER, after that he can rather check the to-do when it's done, or remove it using the delete button.

The user's to-do list is stored in the local storage, so when he refreshes the page, he can always find the list there.

There is the possibility for the user, to clear the list, by clicking the button clear, at the top right corner of our app.

The to do list app, shows the today's date to the user, for that we're using a method called toLocaleDateString, which you can read about here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
for that we're using a method called toLocaleDateString, which you can read about here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

///// Here you can find some other tutorial, that you might like to see /////

Expand Down
50 changes: 49 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
<!-- CODE EXPLAINED CHANNEL -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To-Do App</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web" >
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

</head>
<body>
<div class="container">

<div class="header">
<div class="clear">
<i class="fa fa-refresh" aria-hidden="true"></i>
</div>
<div>
<center><h2 style="color:beige">Your To-Do list</h2></center>
<div id="MyClockDisplay" class="clock" onload="showTime()">99</div>
</div>
<div id="date">hello</div>
</div>

<div class="content">
<ul id="list">

<!-- <li class="item">
<i class="fa fa-circle-thin co" job="complete" id="0"></i>
<p class="text">Drink Coffee</p>
<i class="fa fa-trash-o de" job="delete" id="0"></i>

</li>-->

</ul>
</div>
<div class="add-to-do">
<!-- <i class="fa fa-plus-circle" aria-hidden="true"></i> -->

<img id="foo" src="https://img.icons8.com/cute-clipart/64/000000/plus.png" />
<input type="text" id="input" placeholder="Add a to-do">


</div>
</div>
</body>
<script src="todo.js"></script>
</html>
223 changes: 222 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,222 @@
// CODE EXPLAINED channel
// CODE EXPLAINED channel


function myFunction() {
var d = new Date();
console.log(d);
var weekday = new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thrusday";
weekday[5]="Friday";
weekday[6]="Saturday";

var month = new Array(11);
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "Aug";
month[8] = "Sept";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";

var mon = month[d.getMonth()];
var day = weekday[d.getDay()];
var date = d.getDate();
document.getElementById("date").innerHTML = day +", "+ mon + " "+date ;
}

myFunction();

function showTime(){
var date = new Date();
var h = date.getHours(); // 0 - 23
var m = date.getMinutes(); // 0 - 59

var session = "AM";

if(h == 0){
h = 12;
}

if(h > 12){
h = h - 12;
session = "PM";
}

h = (h < 10) ? "0" + h : h;
m = (m < 10) ? "0" + m : m;


var time = h + ":" + m + ":" + " " + session;
document.getElementById("MyClockDisplay").innerText = time;
document.getElementById("MyClockDisplay").textContent = time;

setTimeout(showTime, 1000);

}

showTime();

// showing data in todolist
const clear = document.querySelector(".clear");
const list= document.getElementById("list");
const input=document.getElementById('input');

const check = "fa-check-circle";
const uncheck = "fa-circle-thin";
const linethrough="lineThrough";
let LIST, id;


//get item
let data = localStorage.getItem("storeitem");

if(data)
{
LIST =JSON.parse(data);
id=LIST.length;
loadList(LIST);

}
else{
LIST=[];
id=0;
}

function loadList(array){
array.forEach(function(item){
add(item.name,item.id,item.done,item.trash);
});
}
//clear
clear.addEventListener("click",function(){
localStorage.clear();
location.reload();
})



function add(todo,id,done,trash){


if(trash){
return;
}
const don = done ? check:uncheck;
const line = done ? linethrough:"";

const item = `<li class="item">
<i class="fa ${don} co" job="complete" id="${id}"></i>
<p class="text ${line}">${todo}</p>
<i class="fa fa-trash-o de" job="delete" id="${id}"></i>
</li>`;

const position="beforeend";

list.insertAdjacentHTML(position, item);
}



document.addEventListener("keyup",function(even){
if(event.keyCode==13)
{
const todo = input.value;

if(todo=="")
{
alert('ERROR :Please Input a task')
}

if(todo)
{
add(todo, id, false,false);

LIST.push({
name:todo,
id:id,
done:false,
trash:false
});
localStorage.setItem("storeitem",JSON.stringify(LIST));
id++;

}
input.value="";

}
});


const btu= document.getElementById('foo');

btu.addEventListener("click",function(cgata){


const todo = input.value;

if(todo=="")
{
alert('ERROR :Please Input a task')
}

if(todo)
{
add(todo, id, false,false);

LIST.push({
name:todo,
id:id,
done:false,
trash:false
});
id++;

}
input.value="";

})


function completeto(element)
{
element.classList.toggle(check);
element.classList.toggle(uncheck);
element.parentNode.querySelector(".text").classList.toggle(linethrough);

LIST[element.id].done =LIST[element.id].done?false:true;
}


function removeto(element)
{
element.parentNode.parentNode.removeChild(element.parentNode);
LIST[element.id].trash=true;

}


list.addEventListener("click",function(event){
const element = event.target;
const elementjob = element.attributes.job.value;

if(elementjob=="complete")
{
completeto(element);

}
else if(elementjob=="delete")
{
removeto(element);
}

localStorage.setItem("storeitem",JSON.stringify(LIST));
});