File tree Expand file tree Collapse file tree 2 files changed +48
-6
lines changed
Expand file tree Collapse file tree 2 files changed +48
-6
lines changed Original file line number Diff line number Diff line change 55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
66 < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
77 < title > Document</ title >
8+ < link rel ="stylesheet " href ="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css " integrity ="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T " crossorigin ="anonymous ">
89</ head >
910< style >
1011 .striked {
1112 text-decoration : line-through;
1213 }
14+ ul > li : hover {
15+ cursor : pointer;
16+ }
1317</ style >
1418< body >
15- < input id ="newTodo " type ="text " placeholder ="Add new todo ">
16- < button onclick ="addTodo() "> ADD +</ button >
19+ < div class ="container mt-5 ">
20+ < div class ="row ">
21+ < div class ="col-8 form-group ">
22+ < input class ="form-control " id ="newTodo " type ="text " placeholder ="Today i must... ">
23+ < small class ="form-text text-muted "> Add a new todo</ small >
24+ </ div >
25+ < div class ="col-4 ">
26+ < div class ="flex-row justify-content-center align-items-center ">
27+ < button class ="btn btn-primary mt-1 mt-md-0 " onclick ="addTodo() "> ADD +</ button >
28+ < button class ="btn btn-secondary mt-1 mt-md-0 " > Reset</ button >
29+ < button class ="btn btn-danger mt-1 " onclick ="removeTodos() "> Bin</ button >
30+ </ div >
31+ </ div >
32+ </ div >
33+
34+ < div class ="row mt-2 ">
35+ < div class ="col-10 offset-1 ">
36+ < ul class ="list-group ">
37+
38+ </ ul >
39+ </ div >
40+
41+ </ div >
42+
1743
18- < ul >
44+ </ div >
1945
20- </ ul >
2146
2247 < script src ="https://code.jquery.com/jquery-3.4.1.min.js "> </ script >
2348 < script src ="index.js " defer > </ script >
Original file line number Diff line number Diff line change 1- const todos = [
1+ let todos = [
22 {
33 id : 1 ,
44 name : "Teach Class at Nagarro" ,
@@ -14,7 +14,10 @@ const todos = [
1414function render ( state ) {
1515 return state
1616 . map ( todo => {
17- const classString = todo . done ? `class = "striked"` : ''
17+ // const li = document.createElement('li')
18+ // li.classList.add("striked")
19+ // document.body.append(li)
20+ const classString = todo . done ? `class = "list-group-item striked"` : `class = "list-group-item"`
1821 return `<li data-todo="${ todo . id } " ${ classString } > ${ todo . name } </li>` ;
1922 } )
2023 . join ( "" ) ;
@@ -39,6 +42,14 @@ function addTodo() {
3942}
4043
4144
45+
46+ function removeTodos ( ) {
47+ todos = todos . filter ( todo => ! todo . done )
48+
49+ paint ( )
50+ }
51+
52+
4253$ ( 'ul' ) . on ( "click" , function ( e ) {
4354 const idToFind = e . target . dataset . todo
4455 const todo = todos . find ( todo => todo . id == idToFind )
@@ -47,4 +58,10 @@ $('ul').on("click", function (e) {
4758 paint ( )
4859} )
4960
61+ $ ( '#newTodo' ) . on ( "keypress" , function ( e ) {
62+ if ( e . which == 13 ) {
63+ addTodo ( )
64+ }
65+ } )
66+
5067paint ( ) ;
You can’t perform that action at this time.
0 commit comments