diff --git a/app.js b/app.js index ab737a6002..4178e66bb2 100644 --- a/app.js +++ b/app.js @@ -8,187 +8,182 @@ // 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 +let taskInput = document.getElementById("new-task");//Add a new task. +let addButton = document.getElementsByTagName("button")[0];//first button +let incompleteTaskHolder = document.querySelector(".incompleted-tasks");//ul of #incompleteTasks +let completedTasksHolder = document.querySelector(".completed-tasks");//completed-tasks +let forms = document.querySelectorAll("form"); //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; +let createNewTaskElement = function (taskString) { + let listItem = document.createElement("li"); + let checkBox = document.createElement("input"); // INPUT + let label = document.createElement("label"); //LABEL + let editInput = document.createElement("input"); //TEXT + let editButton = document.createElement("button");//EDIT BUTTON + //button.delete + let deleteButton = document.createElement("button");//DELETE BUTTON + let deleteButtonImg = document.createElement("img");//DELETE BUTTON IMAGE + //LI + listItem.className = 'list__item'; + //LABEL SETTINGS + label.innerText = taskString; + label.className = "label list__label"; + //INPUT SETTINGS + checkBox.type = "checkbox"; + checkBox.className = "input_check"; + editInput.type = "text"; + editInput.className = "input"; + //EDIT BUTTON SETTINGS + editButton.innerText = "Edit"; + editButton.className = "edit button"; + //DELETE BUTTON + deleteButton.className = "delete button"; + deleteButtonImg.src = "./remove.svg"; + deleteButtonImg.className = "button__image"; + deleteButton.appendChild(deleteButtonImg); + //APPENDING TO LI + 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); +let addTask = function () { + if (!taskInput.value) return; + let listItem = createNewTaskElement(taskInput.value); - //Append listItem to incompleteTaskHolder - incompleteTaskHolder.appendChild(listItem); - bindTaskEvents(listItem, taskCompleted); - - 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'"); +let editTask = function () { + console.log("Edit Task..."); + console.log("Change 'edit' to 'save'"); - var listItem=this.parentNode; + let 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){ + let editInput = listItem.querySelector("input[type=text]"); + let label = listItem.querySelector("label"); + let editBtn = listItem.querySelector(".edit"); + let containsClass = listItem.classList.contains("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"; - } + //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"); + //toggle .editmode on the parent. + listItem.classList.toggle("edit-mode"); + editInput.focus(); }; //Delete task. -var deleteTask=function(){ - console.log("Delete Task..."); +let 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); + let listItem = this.parentNode; + let ul = listItem.parentNode; + //Remove the parent list item from the ul. + ul.removeChild(listItem); } //Mark task completed -var taskCompleted=function(){ - console.log("Complete Task..."); +let 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); + //Append the task list item to the #completed-tasks + let 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); +let taskIncomplete = function () { + console.log("Incomplete Task..."); + //Mark task as incomplete. + //When the checkbox is unchecked + //Append the task list item to the #incompleteTasks. + let listItem = this.parentNode; + incompleteTaskHolder.appendChild(listItem); + bindTaskEvents(listItem, taskCompleted); } -var ajaxRequest=function(){ - console.log("AJAX Request"); +let 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); +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"); +let bindTaskEvents = function (taskListItem, checkBoxEventHandler) { + console.log("bind list item events"); + //select ListItems children + let checkBox = taskListItem.querySelector("input[type=checkbox]"); + let editButton = taskListItem.querySelector("button.edit"); + let 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; + //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 false; } -// Issues with usability don't get seen until they are in front of a human tester. +// Issues with usability don"t get seen until they are in front of a human tester. //prevent creation of empty tasks. diff --git a/index.html b/index.html index ef4aa1f60c..65d5a250ee 100644 --- a/index.html +++ b/index.html @@ -1,19 +1,62 @@ + -Todo App - - - + + + Todo App + + + + -
Want more details?
-

-

Todo

-

Completed

-
- +
+
+ matrix-eisenhower +
+ Want more details? +
+
+
+
+ +
+ + +
+
+
+
+

Todo

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

Completed

+
    +
  • + + + + + +
  • +
+
+
+
+ + \ No newline at end of file diff --git a/style.css b/style.css index ab36227705..ead4032a07 100644 --- a/style.css +++ b/style.css @@ -1,148 +1,170 @@ /* Basic Style */ body { - background-color: #f8f8f8; - color: #333; - font-family: Lato, sans-serif; + background-color: #f8f8f8; + color: #333; + font-family: Lato, sans-serif; } -.aaa { - width: 500px; - margin: 0 auto; - display: block; - text-align: right; -} -.aaa img { - width: 100%; + +.list { + margin: 0; + padding: 0px; } -.aaa .more_inf { - font-family: fantasy, cursive; + +.list__item{ + list-style: none; } -@media (max-width:768px) { -.aaa { text-align: center; +.input, +.button { + outline: none; } + +.button { + background: none; + border: 0px; + color: #888; + font-size: 15px; + width: 60px; + font-family: Lato, sans-serif; + cursor: pointer; } -.centered-main-page-element { - display: block; - width: 500px; - margin: 0 auto 0; + +.button:hover { + color: #3a3a3a; } -.task { - width: 56%; - display: inline-block; - flex-grow: 1 + +.header { + width: 500px; + margin: 0 auto; + display: block; + text-align: right; } -.task-row-wrapper { - display: flex; + +.header__img { + width: 100%; } -ul { - margin:0; - padding: 0px; + +.header__link { + font-family: fantasy, cursive; } -li, h3 { - list-style:none; + +@media (max-width:768px) { + .header { + text-align: center; + } } -input,button{ - outline:none; + +.TODO { + display: block; + width: 500px; + margin: 0 auto 0;; } -button { - background: none; - border: 0px; - color: #888; - font-size: 15px; - width: 60px; - font-family: Lato, sans-serif; - cursor: pointer; + +.input { + width: 56%; + display: inline-block; + flex-grow: 1; } -button:hover { - color: #3a3A3a; + +.task-row-wrapper { + display: flex; } + + /* 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; -} -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; -} -input[type="text"]:focus { - color: #333; +.label_new-task { + color: #333; + font-weight: 700; + font-size: 15px; + border-bottom: 2px solid #333; + padding: 30px 0 10px; + margin: 0; + text-transform: uppercase; +} + +.input { + 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:focus { + color: #333; } /* New Task */ -label[for='new-task'] { - display: block; - margin: 0 0 20px; +.label_new-task { + display: block; + margin: 0 0 20px; } -input#new-task { - width: 318px; + +.input_new-task { + width: 318px; } /* Task list */ -li { - overflow: hidden; - padding: 20px 0; - border-bottom: 1px solid #eee; +.list__item { + overflow: hidden; + padding: 20px 0; + border-bottom: 1px solid #eee; - display: flex; - justify-content: space-between; - align-items: center; + display: flex; + justify-content: space-between; + align-items: center; } -li > * { - vertical-align: middle; + +.list__item>* { + vertical-align: middle; } -li > input[type="checkbox"] { - margin: 0 10px; +.input_check { + margin: 0 10px; } -li > label { - padding-left: 10px; - box-sizing: border-box; - font-size: 18px; - width: 226px; + +.list__label { + padding-left: 10px; + box-sizing: border-box; + font-size: 18px; + width: 226px; } -li > input[type="text"] { - width: 226px + +.list__input { + width: 226px; } -button.delete img { - height: 2em; - transform: rotateZ(45deg); - transition: transform 200ms ease-in; + +.button__image { + height: 2em; + transform: rotateZ(45deg); + transition: transform 200ms ease-in; } -button.delete img:hover { - transform: rotateZ(0); + +.button__image:hover { + transform: rotateZ(0); } /* Completed */ -ul#completed-tasks label { - text-decoration: line-through - color: #888; +.completed-tasks .label { + text-decoration: line-through; + color: #888; } -/* Edit Task */ -ul li input[type=text] { - display:none +.list .input[type="text"] { + display: none; } -ul li.editMode input[type=text] { - display:inline-block; - width:224px +.edit-mode .input[type="text"] { + display: inline-block; + width: 224px; } -ul li.editMode label { - display:none; -} \ No newline at end of file +.edit-mode .label { + display: none; +}