Skip to content

Commit 68eea5e

Browse files
authored
Update index.js
1 parent 39545dc commit 68eea5e

File tree

1 file changed

+26
-67
lines changed

1 file changed

+26
-67
lines changed

spa/index.js

Lines changed: 26 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,26 @@
1-
let todos = [
2-
{
3-
id: 1,
4-
name: "Teach Class at Nagarro",
5-
done: true
6-
},
7-
{
8-
id: 2,
9-
name: "Get Coffee",
10-
done: false
11-
}
12-
];
13-
14-
function render(state) {
15-
return state
16-
.map(todo => {
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"`
21-
return `<li data-todo="${todo.id}" ${classString}> ${todo.name} </li>`;
22-
})
23-
.join("");
24-
}
25-
26-
function paint() {
27-
$("ul").html(render(todos));
28-
}
29-
30-
function addTodo() {
31-
// document.getElementById('newTodo') != $('#newTodo')
32-
const inputBox = $('#newTodo')
33-
todos.push({
34-
id: todos.length + 1,
35-
name: inputBox.val(),
36-
done: false
37-
})
38-
39-
inputBox.val('')
40-
41-
paint()
42-
}
43-
44-
45-
46-
function removeTodos() {
47-
todos = todos.filter(todo => !todo.done)
48-
49-
paint()
50-
}
51-
52-
53-
$('ul').on("click", function (e) {
54-
const idToFind = e.target.dataset.todo
55-
const todo = todos.find(todo => todo.id == idToFind)
56-
todo.done = !todo.done
57-
58-
paint()
59-
})
60-
61-
$('#newTodo').on("keypress", function (e) {
62-
if (e.which == 13) {
63-
addTodo()
64-
}
65-
})
66-
67-
paint();
1+
$(document).ready(
2+
function(){
3+
$('#button').click(
4+
function(){
5+
var toAdd = $('input[name=ListItem]').val();
6+
$('ol').append('<li>' + toAdd + '</li>');
7+
});
8+
9+
$("input[name=ListItem]").keyup(function(event){
10+
if(event.keyCode == 13){
11+
$("#button").click();
12+
}
13+
});
14+
15+
$(document).on('dblclick','li', function(){
16+
$(this).toggleClass('strike').fadeOut('slow');
17+
});
18+
19+
$('input').focus(function() {
20+
$(this).val('');
21+
});
22+
23+
$('ol').sortable();
24+
25+
}
26+
);

0 commit comments

Comments
 (0)