diff --git a/app.js b/app.js index ab737a600..1f38204f3 100644 --- a/app.js +++ b/app.js @@ -5,191 +5,171 @@ //Solution: Add interactivity so the user can manage daily tasks. //Break things down into smaller steps and take each step at a time. - // Event handling, user interaction is what starts the code execution. -var taskInput=document.getElementById("new-task");//Add a new task. -var addButton=document.getElementsByTagName("button")[0];//first button -var incompleteTaskHolder=document.getElementById("incompleteTasks");//ul of #incompleteTasks -var completedTasksHolder=document.getElementById("completed-tasks");//completed-tasks - +var taskInput = document.getElementById("new-task"); //Add a new task. +var addButton = document.getElementsByTagName("button")[0]; //first button +//var incompleteTaskHolder=document.getElementById("incompleteTasks");//ul of #incompleteTasks +var incompleteTaskHolder = document.getElementById("todo-tasks"); //ul of #todo-tasks +var completedTasksHolder = document.getElementById("completed-tasks"); //completed-tasks //New task list item -var createNewTaskElement=function(taskString){ - - var listItem=document.createElement("li"); - - //input (checkbox) - var checkBox=document.createElement("input");//checkbx - //label - var label=document.createElement("label");//label - //input (text) - var editInput=document.createElement("input");//text - //button.edit - var editButton=document.createElement("button");//edit button - - //button.delete - var deleteButton=document.createElement("button");//delete button - var deleteButtonImg=document.createElement("img");//delete button image - - label.innerText=taskString; - label.className='task'; - - //Each elements, needs appending - checkBox.type="checkbox"; - editInput.type="text"; - editInput.className="task"; - - editButton.innerText="Edit"; //innerText encodes special characters, HTML does not. - editButton.className="edit"; - - deleteButton.className="delete"; - deleteButtonImg.src='./remove.svg'; - deleteButton.appendChild(deleteButtonImg); - - - //and appending. - listItem.appendChild(checkBox); - listItem.appendChild(label); - listItem.appendChild(editInput); - listItem.appendChild(editButton); - listItem.appendChild(deleteButton); - return listItem; -} - - - -var addTask=function(){ - console.log("Add Task..."); - //Create a new list item with the text from the #new-task: - if (!taskInput.value) return; - var listItem=createNewTaskElement(taskInput.value); +var createNewTaskElement = function (taskString) { + var listItem = document.createElement("li"); + + listItem.className = "li"; // не закончил + + //input (checkbox) + var checkBox = document.createElement("input"); //checkbx + //label + var label = document.createElement("label"); //label + //input (text) + var editInput = document.createElement("input"); //text + //button.edit + var editButton = document.createElement("button"); //edit button + + //button.delete + var deleteButton = document.createElement("button"); //delete button + var deleteButtonImg = document.createElement("img"); //delete button image + + label.innerText = taskString; + label.className = "task"; + + //Each elements, needs appending + checkBox.type = "checkbox"; + editInput.type = "text"; + editInput.className = "task task_text"; + + editButton.innerText = "Edit"; //innerText encodes special characters, HTML does not. + editButton.className = "button button_edit"; + + deleteButton.className = "button button_delete"; + deleteButtonImg.src = "./remove.svg"; + deleteButtonImg.className = "button__img_delete"; + deleteButton.appendChild(deleteButtonImg); + + //and appending. + listItem.appendChild(checkBox); + listItem.appendChild(label); + listItem.appendChild(editInput); + listItem.appendChild(editButton); + listItem.appendChild(deleteButton); + return listItem; +}; - //Append listItem to incompleteTaskHolder - incompleteTaskHolder.appendChild(listItem); - bindTaskEvents(listItem, taskCompleted); +var addTask = function () { + console.log("Add Task..."); + //Create a new list item with the text from the #new-task: + if (!taskInput.value) return; + var listItem = createNewTaskElement(taskInput.value); + listItem.className = "li add-label__input"; // не закончил - taskInput.value=""; + //Append listItem to incompleteTaskHolder + incompleteTaskHolder.appendChild(listItem); + bindTaskEvents(listItem, taskCompleted); -} + taskInput.value = ""; +}; //Edit an existing task. -var editTask=function(){ - console.log("Edit Task..."); - console.log("Change 'edit' to 'save'"); - - - var listItem=this.parentNode; - - var editInput=listItem.querySelector('input[type=text]'); - var label=listItem.querySelector("label"); - var editBtn=listItem.querySelector(".edit"); - var containsClass=listItem.classList.contains("editMode"); - //If class of the parent is .editmode - if(containsClass){ - - //switch to .editmode - //label becomes the inputs value. - label.innerText=editInput.value; - editBtn.innerText="Edit"; - }else{ - editInput.value=label.innerText; - editBtn.innerText="Save"; - } - - //toggle .editmode on the parent. - listItem.classList.toggle("editMode"); +var editTask = function () { + console.log("Edit Task..."); + console.log("Change 'edit' to 'save'"); + + var listItem = this.parentNode; + + var editInput = listItem.querySelector("input[type=text]"); + var label = listItem.querySelector("label"); + var editBtn = listItem.querySelector(".button_edit"); + //var containsClass=listItem.classList.contains("editMode"); + var containsClass = listItem.classList.contains("li_edit-mode"); + //If class of the parent is .editmode + if (containsClass) { + //switch to .editmode + //label becomes the inputs value. + label.innerText = editInput.value; + editBtn.innerText = "Edit"; + } else { + editInput.value = label.innerText; + editBtn.innerText = "Save"; + } + + //toggle .editmode on the parent. + listItem.classList.toggle("li_edit-mode"); + //listItem.classList.toggle("editMode"); }; - //Delete task. -var deleteTask=function(){ - console.log("Delete Task..."); - - var listItem=this.parentNode; - var ul=listItem.parentNode; - //Remove the parent list item from the ul. - ul.removeChild(listItem); - -} +var deleteTask = function () { + console.log("Delete Task..."); + var listItem = this.parentNode; + var ul = listItem.parentNode; + //Remove the parent list item from the ul. + ul.removeChild(listItem); +}; //Mark task completed -var taskCompleted=function(){ - console.log("Complete Task..."); - - //Append the task list item to the #completed-tasks - var listItem=this.parentNode; - completedTasksHolder.appendChild(listItem); - bindTaskEvents(listItem, taskIncomplete); - -} - - -var taskIncomplete=function(){ - console.log("Incomplete Task..."); -//Mark task as incomplete. - //When the checkbox is unchecked - //Append the task list item to the #incompleteTasks. - var listItem=this.parentNode; - incompleteTaskHolder.appendChild(listItem); - bindTaskEvents(listItem,taskCompleted); -} +var taskCompleted = function () { + console.log("Complete Task..."); + //Append the task list item to the #completed-tasks + var listItem = this.parentNode; + completedTasksHolder.appendChild(listItem); + bindTaskEvents(listItem, taskIncomplete); +}; +var taskIncomplete = function () { + console.log("Incomplete Task..."); + //Mark task as incomplete. + //When the checkbox is unchecked + //Append the task list item to the #todo-tasks. + var listItem = this.parentNode; + incompleteTaskHolder.appendChild(listItem); + bindTaskEvents(listItem, taskCompleted); +}; -var ajaxRequest=function(){ - console.log("AJAX Request"); -} +var ajaxRequest = function () { + console.log("AJAX Request"); +}; //The glue to hold it all together. - //Set the click handler to the addTask function. -addButton.onclick=addTask; -addButton.addEventListener("click",addTask); -addButton.addEventListener("click",ajaxRequest); - - -var bindTaskEvents=function(taskListItem,checkBoxEventHandler){ - console.log("bind list item events"); -//select ListItems children - var checkBox=taskListItem.querySelector("input[type=checkbox]"); - var editButton=taskListItem.querySelector("button.edit"); - var deleteButton=taskListItem.querySelector("button.delete"); - - - //Bind editTask to edit button. - editButton.onclick=editTask; - //Bind deleteTask to delete button. - deleteButton.onclick=deleteTask; - //Bind taskCompleted to checkBoxEventHandler. - checkBox.onchange=checkBoxEventHandler; -} +addButton.onclick = addTask; +addButton.addEventListener("click", addTask); +addButton.addEventListener("click", ajaxRequest); + +var bindTaskEvents = function (taskListItem, checkBoxEventHandler) { + console.log("bind list item events"); + //select ListItems children + var checkBox = taskListItem.querySelector("input[type=checkbox]"); + var editButton = taskListItem.querySelector("button.button_edit"); + var deleteButton = taskListItem.querySelector("button.button_delete"); + + //Bind editTask to edit button. + editButton.onclick = editTask; + //Bind deleteTask to delete button. + deleteButton.onclick = deleteTask; + //Bind taskCompleted to checkBoxEventHandler. + checkBox.onchange = checkBoxEventHandler; +}; //cycle over incompleteTaskHolder ul list items //for each list item -for (var i=0; i -Todo App - - - + + + + + + + Todo App + + + -
Want more details?
-

-

Todo

-

Completed

-
- + +
+ +
+ +
+
+ +
+

Add Item

+ +
+ + +
+
+ +
+

Todo

+
    +
  • + + + + + +
  • +
  • + + + + + +
  • +
+
+ +
+

Completed

+
    +
  • + + + + + +
  • +
+
+ +
+
+ + \ No newline at end of file diff --git a/style.css b/style.css index ab3622770..004add1cb 100644 --- a/style.css +++ b/style.css @@ -1,148 +1,176 @@ -/* Basic Style */ -body { - background-color: #f8f8f8; - color: #333; - font-family: Lato, sans-serif; -} -.aaa { - width: 500px; - margin: 0 auto; - display: block; - text-align: right; +/* reset CSS style *************/ + +ul { + margin: 0; + padding: 0; } -.aaa img { - width: 100%; + +li, +h3 { + list-style: none; } -.aaa .more_inf { - font-family: fantasy, cursive; + +input, +button { + outline: none; } -@media (max-width:768px) { -.aaa { text-align: center; +/* Basic Style **************/ + +.header, +.main { + background-color: #f8f8f8; + color: #333; + font-family: Lato, sans-serif; } + +.container { + width: 500px; + margin: 0 auto; + display: block; } -.centered-main-page-element { - display: block; - width: 500px; - margin: 0 auto 0; + +.container_header { + text-align: right; } -.task { - width: 56%; - display: inline-block; - flex-grow: 1 + +.header__start-img { + width: 100%; } -.task-row-wrapper { - display: flex; + +.header__link { + font-family: fantasy, cursive; } -ul { - margin:0; - padding: 0px; + +@media (max-width: 768px) { + .container_header { + text-align: center; + } } -li, h3 { - list-style:none; + +.task { + width: 56%; + display: inline-block; + flex-grow: 1; } -input,button{ - outline:none; + +.add-label__wrapper { + display: flex; + justify-content: space-between; } -button { - background: none; - border: 0px; - color: #888; - font-size: 15px; - width: 60px; - font-family: Lato, sans-serif; - cursor: pointer; + +.button { + background: none; + border: 0; + color: #888; + font-size: 15px; + width: 60px; + font-family: Lato, sans-serif; + cursor: pointer; } -button:hover { - color: #3a3A3a; + +.button:hover { + color: #3a3a3a; } -/* Heading */ -h3, -label[for='new-task'] { - color: #333; - font-weight: 700; - font-size: 15px; - border-bottom: 2px solid #333; - padding: 30px 0 10px; - margin: 0; - text-transform: uppercase; + +/* Heading ****************/ + +.title { + color: #333; + font-weight: 700; + font-size: 15px; + border-bottom: 2px solid #333; + padding: 30px 0 10px; + margin: 0; + text-transform: uppercase; } -input[type="text"] { - margin: 0; - font-size: 18px; - line-height: 18px; - height: 21px; - padding: 0 9px; - border: 1px solid #dDd; - background: #FFF; - border-radius: 6px; - font-family: Lato, sans-serif; - color: #888; + +.task_text { + margin: 0; + font-size: 18px; + line-height: 18px; + height: 21px; + padding: 0 9px; + border: 1px solid #ddd; + background: #fff; + border-radius: 6px; + font-family: Lato, sans-serif; + color: #888; } -input[type="text"]:focus { - color: #333; + +.task_text:focus { + color: #333; } -/* New Task */ -label[for='new-task'] { - display: block; - margin: 0 0 20px; +/* New Task ************************/ + +.add-label { + display: block; + margin-bottom: 20px; } -input#new-task { - width: 318px; + +.add-label__input { + width: 318px; } -/* Task list */ -li { - overflow: hidden; - padding: 20px 0; - border-bottom: 1px solid #eee; +/* Task list *********************/ - display: flex; - justify-content: space-between; - align-items: center; +.li { + overflow: hidden; + padding: 20px 0; + border-bottom: 1px solid #eee; + display: flex; + justify-content: space-between; + align-items: center; } -li > * { - vertical-align: middle; + +.li { + vertical-align: middle; } -li > input[type="checkbox"] { - margin: 0 10px; +.li__input-checkbox { + margin: 0 10px; } -li > label { - padding-left: 10px; - box-sizing: border-box; - font-size: 18px; - width: 226px; + +.li__label { + padding-left: 10px; + box-sizing: border-box; + font-size: 18px; + width: 226px; } -li > input[type="text"] { - width: 226px + +.li__input-text { + width: 226px; } -button.delete img { - height: 2em; - transform: rotateZ(45deg); - transition: transform 200ms ease-in; + +.button__img_delete { + height: 2em; + transform: rotateZ(45deg); + transition: transform 200ms ease-in; } -button.delete img:hover { - transform: rotateZ(0); + +.button__img_delete:hover { + transform: rotateZ(0); } -/* Completed */ -ul#completed-tasks label { - text-decoration: line-through - color: #888; +/* Completed ***********************/ + +.completed-tasks .li__label { + text-decoration: line-through; + color: #888; } -/* Edit Task */ -ul li input[type=text] { - display:none +/* Edit Task *************************/ + +.li__input-text { + display: none; } -ul li.editMode input[type=text] { - display:inline-block; - width:224px +.li_edit-mode .li__input-text { + display: inline-block; + width: 224px; } -ul li.editMode label { - display:none; -} \ No newline at end of file +.li_edit-mode .li__label { + display: none; +}