File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ let ulTasks = $('#ulTasks')
2
+ let btnAdd = $('#btnAdd')
3
+ let btnReset = $('#btnReset')
4
+ let btnSort = $('#btnSort')
5
+ let btnCleanup = $('#btnCleanup')
6
+ let inpNewTask = $('#inpNewTask')
7
+
8
+ function addItem() {
9
+ let listItem = $('<li>', {
10
+ 'class': 'list-group-item',
11
+ text: inpNewTask.val()
12
+ })
13
+ listItem.click(() => {
14
+ listItem.toggleClass('done')
15
+ })
16
+ ulTasks.append(listItem)
17
+ inpNewTask.val('')
18
+ toggleInputButtons()
19
+ }
20
+
21
+ function clearDone() {
22
+ $('#ulTasks .done').remove()
23
+ toggleInputButtons()
24
+ }
25
+
26
+ function sortTasks() {
27
+ $('#ulTasks .done').appendTo(ulTasks)
28
+ }
29
+
30
+ function toggleInputButtons() {
31
+ btnReset.prop('disabled', inpNewTask.val() == '')
32
+ btnAdd.prop('disabled', inpNewTask.val() == '')
33
+ btnSort.prop('disabled', ulTasks.children().length < 1)
34
+ btnCleanup.prop('disabled', ulTasks.children().length < 1)
35
+ }
36
+
37
+ inpNewTask.keypress((e) => {
38
+ if (e.which == 13) addItem()
39
+ })
40
+ inpNewTask.on('input', toggleInputButtons)
41
+
42
+ btnAdd.click(addItem)
43
+ btnReset.click(() => {
44
+ inpNewTask.val('')
45
+ toggleInputButtons()
46
+ })
47
+ btnCleanup.click(clearDone)
48
+ btnSort.click(sortTasks)
You can’t perform that action at this time.
0 commit comments