-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (42 loc) · 1.06 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
let ulTasks = $('#ulTasks')
let btnAdd = $('#btnAdd')
let btnReset = $('#btnReset')
let btnSort = $('#btnSort')
let btnCleanup = $('#btnCleanup')
let inpNewTask = $('#inpNewTask')
function addItem() {
let listItem = $('<li>', {
'class': 'list-group-item',
text: inpNewTask.val()
})
listItem.click(() => {
listItem.toggleClass('done')
})
ulTasks.append(listItem)
inpNewTask.val('')
toggleInputButtons()
}
function clearDone() {
$('#ulTasks .done').remove()
toggleInputButtons()
}
function sortTasks() {
$('#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)
}
inpNewTask.keypress((e) => {
if (e.which == 13) addItem()
})
inpNewTask.on('input', toggleInputButtons)
btnAdd.click(addItem)
btnReset.click(() => {
inpNewTask.val('')
toggleInputButtons()
})
btnCleanup.click(clearDone)
btnSort.click(sortTasks)