Skip to content
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

Clean code s1e1 #109

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
73c75a9
init: init project
Volodia34 Dec 12, 2024
99131e0
fix(basic-2.2): add Html5 DOCTYPE tag
Volodia34 Dec 16, 2024
8436c5b
refactor(basic-2.4): delete type attribute for scripts and styles
Volodia34 Dec 16, 2024
58d69ef
refactor(basic-1.2): convert uppercase letters to lowercase
Volodia34 Dec 16, 2024
ec30282
refactor(basic-1.3): replace single quotes with double quotes
Volodia34 Dec 16, 2024
8c8250d
refactor(basic-2.1): adjust indentation to respect the nesting hierarchy
Volodia34 Dec 16, 2024
fb3addc
refactor(basic-2.3): update named character reference
Volodia34 Dec 16, 2024
1a1d378
fix(basic(2-1)
Volodia34 Dec 16, 2024
225afb3
fix(html-2.5): break long HTML lines into multiple lines for readability
Volodia34 Dec 16, 2024
3766022
refactor(basic-3.5): make hierarchy in media block
Volodia34 Dec 17, 2024
89028e2
refactor(basic-3.6): ensure consistent spacing after property names
Volodia34 Dec 17, 2024
c582d90
refactor(basic-3.7): add semicolon after each property
Volodia34 Dec 17, 2024
5014e60
refactor(basic-3.7): ensure semicolon usage after properties
Volodia34 Dec 17, 2024
d8d95a9
refactor(basic-3.1): rename css selectors in the kebab-case style and…
Volodia34 Dec 17, 2024
2596564
refactor(basic-3.3): rename identifiers and classes to concise ones
Volodia34 Dec 17, 2024
6d65c7d
style(basic-1.1): convert tabs to two spaces for consistent indentation
Volodia34 Dec 17, 2024
5d5f4b2
style(basic-1.1): convert tabs to two spaces for consistent indentation
Volodia34 Dec 17, 2024
829f601
style(basic-3.8): separate selectors and properties with a line break
Volodia34 Dec 17, 2024
918071e
refactor(extended-1.1): add semantic tags and fix heading hierarchy
Volodia34 Dec 17, 2024
3a69fc8
fix(extended-1.2): add alternative text for images
Volodia34 Dec 17, 2024
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

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

12 changes: 12 additions & 0 deletions .idea/clean-code-s1e1.iml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

58 changes: 30 additions & 28 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//Document is the DOM can be accessed in the console with document.window.
// Tree is from the top, html, body, p etc.

Expand All @@ -9,42 +10,45 @@
// 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 addButton=document.getElementsByClassName("task-btn")[0];//first button
var incompleteTaskHolder=document.getElementById("incomplete-tasks");//ul of #incomplete-tasks
var completedTasksHolder=document.getElementById("completed-tasks");//completed-tasks


//New task list item
var createNewTaskElement=function(taskString){

var listItem=document.createElement("li");
listItem.className = "task-list-item";

//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.edit-task
var editButton=document.createElement("button");//edit-task button

//button.delete
var deleteButton=document.createElement("button");//delete button
var deleteButtonImg=document.createElement("img");//delete button image
//button.delete-task
var deleteButton=document.createElement("button");//delete-task button
var deleteButtonImg=document.createElement("img");//delete-task button image

label.innerText=taskString;
label.className='task';
label.className='task task-label';

//Each elements, needs appending
checkBox.type="checkbox";
checkBox.className = "task-checkbox";
editInput.type="text";
editInput.className="task";
editInput.className="task task-text";

editButton.innerText="Edit"; //innerText encodes special characters, HTML does not.
editButton.className="edit";
editButton.className="task-btn edit-task";

deleteButton.className="delete";
deleteButton.className="task-btn delete-task";
deleteButtonImg.src='./remove.svg';
deleteButtonImg.className = "delete-task-img";
deleteButton.appendChild(deleteButtonImg);


Expand Down Expand Up @@ -82,14 +86,14 @@ var editTask=function(){

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
var editInput=listItem.querySelector('.task-text');
var label=listItem.querySelector(".task-label");
var editBtn=listItem.querySelector(".edit-task");
var containsClass=listItem.classList.contains("edit-mode");
//If class of the parent is .edit-mode
if(containsClass){

//switch to .editmode
//switch to .edit-mode
//label becomes the inputs value.
label.innerText=editInput.value;
editBtn.innerText="Edit";
Expand All @@ -98,8 +102,8 @@ var editTask=function(){
editBtn.innerText="Save";
}

//toggle .editmode on the parent.
listItem.classList.toggle("editMode");
//toggle .edit-mode on the parent.
listItem.classList.toggle("edit-mode");
};


Expand Down Expand Up @@ -131,7 +135,7 @@ var taskIncomplete=function(){
console.log("Incomplete Task...");
//Mark task as incomplete.
//When the checkbox is unchecked
//Append the task list item to the #incompleteTasks.
//Append the task list item to the #incomplete-tasks.
var listItem=this.parentNode;
incompleteTaskHolder.appendChild(listItem);
bindTaskEvents(listItem,taskCompleted);
Expand All @@ -155,14 +159,14 @@ 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");
var checkBox=taskListItem.querySelector(".task-checkbox");
var editButton=taskListItem.querySelector(".task-btn.edit-task");
var deleteButton=taskListItem.querySelector(".task-btn.delete-task");


//Bind editTask to edit button.
//Bind editTask to edit-task button.
editButton.onclick=editTask;
//Bind deleteTask to delete button.
//Bind deleteTask to delete-task button.
deleteButton.onclick=deleteTask;
//Bind taskCompleted to checkBoxEventHandler.
checkBox.onchange=checkBoxEventHandler;
Expand Down Expand Up @@ -190,6 +194,4 @@ for (var i=0; i<completedTasksHolder.children.length;i++){

// Issues with usability don't get seen until they are in front of a human tester.

//prevent creation of empty tasks.

//Change edit to save when you are in edit mode.
//prevent creation of empty tasks.
82 changes: 66 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
<!DOCTYPE html>
<html>
<HEAD><title>Todo App</title>
<link href='https://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="style.css" type="text/css" MEDIA="screen" charset="utf-8">
</HEAD>
<body>
<div class="aaa"><img src="./eisenhower-matrix.jpg"><a class='more_inf' href="https://goal-life.com/page/method/matrix-eisenhower">Want more details&quest;</a></div>
<div class="centered-main-page-element"><p id='topSectionForAddingElementToList'><label for="new-task">Add Item</label><div class="task-row-wrapper"><input id='new-task'class="task" type="text"><button>Add</button></div>
</p><h3>Todo</h3>
<ul id='incompleteTasks'>
<li><input type='checkbox'><label class="task">Pay Bills</label><input type="text" class="task"><button class="edit">Edit</button><button class="delete"><img src="./remove.svg"></button></li>
<li class="editMode"><input type="checkbox"><label class="task">Go Shopping</label><input type="text" value="Go Shopping" class="task"><button class='edit'>Save</button><button class="delete"><img src="./remove.svg"></button></li>
</ul><h3>Completed</h3><ul id="completed-tasks"><li><input type="checkbox" checked><label class="task">See the Doctor</label><input type="text" class="task"><button class="edit">Edit</button><button class="delete"><img src="./remove.svg"></button>
</li>
</ul>
</div>
<script type="text/javascript" SRC="app.js"></script>
<head>
<title>Todo App</title>
<link
href="https://fonts.googleapis.com/css?family=Lato:300,400,700"
rel="stylesheet"
>
<link
rel="stylesheet"
href="style.css"
media="screen"
charset="utf-8"
>
</head>
<body class="page">
<header class="header">
<img class="header-img" src="./eisenhower-matrix.jpg" alt="Eisenhower Matrix">
<a class="more-info" href="https://goal-life.com/page/method/matrix-eisenhower">Want more details?</a>
</header>
<main class="main">
<section id="add-tasks">
<h2 class="add-tasks-header">Add Item</h2>
<div class="task-row-wrapper">
<input id="new-task" class="task task-text" type="text" aria-label="New task">
<button class="task-btn">Add</button>
</div>
</section>
<section>
<h3 class="task-list-header">Todo</h3>
<ul class="task-list" id="incomplete-tasks">
<li class="task-list-item">
<input type="checkbox" class="task-checkbox" aria-label="Mark task as complete">
<label class="task task-label">Pay Bills</label>
<input type="text" class="task task-text" aria-label="Edit task">
<button class="task-btn edit-task">Edit</button>
<button class="task-btn delete-task">
<img class="delete-task-img" src="./remove.svg" alt="Delete task">
</button>
</li>
<li class="task-list-item edit-mode">
<input type="checkbox" class="task-checkbox" aria-label="Mark task as complete">
<label class="task task-label">Go Shopping</label>
<input type="text" value="Go Shopping" class="task task-text" aria-label="Edit task">
<button class="task-btn edit-task">Save</button>
<button class="task-btn delete-task">
<img class="delete-task-img" src="./remove.svg" alt="Delete task">
</button>
</li>
</ul>
</section>
<section>
<h3 class="task-list-header">Completed</h3>
<ul class="task-list" id="completed-tasks">
<li class="task-list-item">
<input type="checkbox" checked class="task-checkbox" aria-label="Mark task as incomplete">
<label class="task task-label">See the Doctor</label>
<input type="text" class="task task-text" aria-label="Edit task">
<button class="task-btn edit-task">Edit</button>
<button class="task-btn delete-task">
<img class="delete-task-img" src="./remove.svg" alt="Delete task">
</button>
</li>
</ul>
</section>
</main>
<script src="app.js"></script>
</body>
</html>
Loading