-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
61 lines (45 loc) · 1.36 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
let inpNewTask = $("#inpNewTask");
let btnAdd = $("#btnAdd");
let btnReset = $("#btnReset");
let btnSort = $("#btnSort");
let btnCleanup = $("#btnCleanup");
let ulTasks = $("#ulTasks");
function addItem() {
let listItem = $('<li>', {'class': 'list-group-item', text: inpNewTask.val()})
//setting the class of list item to disabled (on click)
listItem.click(() => {
listItem.toggleClass('done')
})
//appending the task to the list
ulTasks.append(listItem)
//resetting the input box to empty string
inpNewTask.val('')
//for btnSort and btnCleanup
toggleInputButtons()
}
function clearDone() {
$('#ulTasks .done').remove()
//for btnSort and btnCleanup
toggleInputButtons()
}
function sortTask() {
$('#ulTasks .done').appendTo(ulTasks)
}
function toggleInputButtons() {
btnReset.prop('disabled', inpNewTask.val() == '')
btnAdd.prop('disabled', inpNewTask.val() == '')
btnSort.prop('disabled', ulTasks.children().length < 1)
btnCleanup.prop('disabled', ulTasks.children().length < 1)
}
//Handling "enter" keypress
inpNewTask.keypress((key) => {
if (key.which == 13) addItem()
})
inpNewTask.on('input', toggleInputButtons)
btnAdd.click(() => addItem());
btnReset.click(() => {
inpNewTask.val('')
toggleInputButtons()
})
btnCleanup.click(() => clearDone())
btnSort.click(() => sortTask())