Skip to content

Final #11

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 1 commit 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
38 changes: 38 additions & 0 deletions Kirill Zhuck/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="styles.css">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<div class="app">
<div class="app__header">
<div class="app__title"><span class="app__title-text">To Do List</span></div>
<div class="app__info">
<div class="app__info-item">
<span class="app__info-text">Tasks</span>
<span class="app__info-number" id="js-all-tasks"></span>
</div>
<div class="app__info-item">
<span class="app__info-text">Done</span>
<span class="app__info-number" id="js-done-tasks"></span>
</div>
</div>
</div>
<div class="app__body">
<ul class="app__list" id="app__list"></ul>
</div>
<div class="app__footer">
<input class="app__task-new" id="app__task-new" placeholder="Add new task">
</div>
</div>
</div>

<script src="script.js"></script>
</body>
</html>
120 changes: 120 additions & 0 deletions Kirill Zhuck/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
(function () {
let tasks = {
current: [{
taskId: doId(),
taskContent: "Buy products",
taskState: "current"
}, {
taskId: doId(),
taskContent: "Build a house",
taskState: "current"
}],
done: [{
taskId: doId(),
taskContent: "Burn everything to hell",
taskState: "done"
}],
get allTasks() {
return this.current.length + this.done.length;
},
get doneTasks() {
return this.done.length;
}
},
tasksList = document.getElementById("app__list"),
allTasks = document.getElementById("js-all-tasks"),
doneTasks = document.getElementById("js-done-tasks"),
addNewTaskField = document.getElementById("app__task-new");

function INIT() {
for (const item of tasks.current) {
createItem(item);
}
for (const item of tasks.done) {
createItem(item);
}
allTasks.innerHTML = tasks.allTasks;
doneTasks.innerHTML = tasks.doneTasks;
}

function createItem(el) {
let item = document.createElement('li'),
remove = document.createElement('div'),
text = document.createElement('span');
remove.classList.add('app__list-remove');
remove.addEventListener('click', function () {
removeTask(this);
});
text.classList.add('app__list-text');
text.addEventListener('click', function () {
doneTask(this);
});
switch (el.taskState) {
case 'done':
item.classList.add('app__list-item', 'app__list-item--done');
break;
default:
item.classList.add('app__list-item');
}
item.id = el.taskId;
text.innerHTML = el.taskContent;
item.appendChild(text);
item.appendChild(remove);
tasksList.appendChild(item);
}

function doneTask(el) {
let elem = el.parentNode,
elemId = elem.id,
elemState = elem.classList.contains('app__list-item--done');

const [itemsRemove, itemsAdd] = elemState ? [tasks.done, tasks.current] : [tasks.current, tasks.done];
elem.classList.toggle('app__list-item--done');
for (const [index, item] of itemsRemove.entries()) {
if (item.taskId !== elemId) continue;
itemsAdd.push(item);
itemsRemove.splice(index, 1);
}
doneTasks.innerHTML = tasks.doneTasks;
}

function removeTask(el) {
let removeEl = el.parentNode,
removeElId = removeEl.id,
removeElState = removeEl.classList.contains('app__list-item--done');

removeEl.remove();
const items = removeElState ? tasks.done : tasks.current;
for (const [index, item] of items.entries()) {
if (item.taskId !== removeElId) continue;
items.splice(index, 1);
}
allTasks.innerHTML = tasks.allTasks;
doneTasks.innerHTML = tasks.doneTasks;
}

function addTasks(str) {
let elem = {
taskId: doId(),
taskContent: str,
taskState: "current"
};
tasks.current.push(elem);
createItem(elem);
allTasks.innerHTML = tasks.allTasks;
}

function doId() {
return Math.random().toString(36).substr(2, 16);
}

INIT();

addNewTaskField.addEventListener('keyup',function (e) {
if(e.keyCode === 13) {
addTasks(this.value);
this.value = "";
}
})

})();
146 changes: 146 additions & 0 deletions Kirill Zhuck/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
html,
body {
height: 100%;
}

body {
background-image: url("./tristan-gevaux-ATtLrdUekdI-unsplash.jpg") ;
background-size: 100%;
margin: 0;
padding: 0;
}

* {
box-sizing: border-box;
}

ul,
li {
padding: 0;
margin: 0;
list-style-type: none;
}

.wrapper {
align-items: center;
display: flex;
justify-content: center;
height: 100%;
}

.app {
box-shadow: 0 0 1px 0 black;
display: flex;
flex-direction: column;
max-width: 500px;
width: 100%;
}

.app__header {
background-color: #ccc;
}

.app__title {
font-size: 20px;
font-weight: 600;
padding: 8px 16px;
text-align: center;
}

.app__info {
display: flex;
padding: 8px 16px;
}

.app__info-item {
align-items: center;
display: flex;
flex-direction: column;
flex: 1;
}

.app__body {
background-color: #ddd;
}

.app__footer {
background-color: #ccc;
padding: 8px 16px;
}

.app__list-item {
align-items: center;
display: flex;
position: relative;
}

.app__list-item:hover {
background-color: #fff;
}

.app__list-item:hover .app__list-remove {
opacity: 0.5;
}

.app__list-item:hover .app__list-remove:hover {
opacity: 1;
}

.app__list-item.app__list-item--done {
background-color: #8fc579;
}

.app__list-item.app__list-item--done .app__list-text {
text-decoration: line-through;
}

.app__list-text {
cursor: pointer;
flex: 1;
line-height: 24px;
padding: 8px 16px;
}

.app__list-remove {
border: 1px solid red;
border-radius: 50%;
cursor: pointer;
height: 32px;
fles-shrink: 0;
margin-left: auto;
margin-right: 5px;
opacity: 0;
padding: 0 8px;
transform: rotate(45deg);
transition: all linear 0.3s;
width: 32px;
}

.app__list-remove:before, .app__list-remove:after {
content: "";
background-color: red;
display: block;
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}

.app__list-remove:before {
height: 3px;
width: 20px;
}

.app__list-remove:after {
height: 20px;
width: 3px;
}

.app__task-new {
border: 0;
line-height: 40px;
min-height: 40px;
padding: 0 8px;
width: 100%;
}

7 changes: 7 additions & 0 deletions Kirill Zhuck/styles.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading