-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
109 lines (90 loc) · 3.25 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function createTodo(text) {
var markUp = '<li class="list-group-item"><input id="todo-checkbox" type="checkbox" value=""><label for="todo-checkbox">' + text + '</label></li>';
$('.todo-list').append(markUp);
$('.todo-add').val("");
}
$(document).ready(function () {
var checkedItems = $('.todo-list input[type=checkbox]:not(:checked)').length;
$('#todo-items').html(checkedItems + " ");
var buttonLightMode = $('body');
$('.btn-light-mode').click(function(e) {
e.preventDefault();
if ($('body').hasClass('dark-mode')) {
$('body').removeClass('dark-mode');
$('#todo-icon').attr('src', '/images/icon-sun.svg');
} else {
$('body').addClass('dark-mode');
$('#todo-icon').attr('src', '/images/icon-moon.svg');
}
});
$('.todo-add').keypress(function(e) {
e.preventDefault;
if (e.which == 13) {
var addToList = $(this).val();
createTodo(addToList);
}
});
$('.todo-list input[type=checkbox]').change(function() {
if (this.checked){
$(this).parent().find('label').addClass('isDone');
} else {
$(this).parent().find('label').removeClass('isDone');
}
var checkedItems = $('.todo-list input[type=checkbox]:not(:checked)').length;
$('#todo-items').html(checkedItems + " ");
})
$('.todo-list label').click(function(e) {
e.preventDefault();
})
var activeStates = $('.todo-filter a');
$('#delete-todo').click(function(e) {
e.preventDefault();
var completedItems = $('.todo-list input[type=checkbox]');
$(completedItems).each(function() {
if ($(this).is(':checked')) {
$(this).parent().remove();
}
})
});
$('#all-todo').click(function(e) {
e.preventDefault();
$(this).addClass('active');
$(activeStates).not(this).each(function() {
$(this).removeClass('active');
})
var completedItems = $('.todo-list input[type=checkbox]');
$(completedItems).each(function() {
$(this).parent().show();
})
});
$('#active-todo').click(function(e) {
e.preventDefault();
$(this).addClass('active');
$(activeStates).not(this).each(function() {
$(this).removeClass('active');
})
var completedItems = $('.todo-list input[type=checkbox]');
$(completedItems).each(function() {
if (!($(this).is(':checked'))) {
$(this).parent().show();
} else {
$(this).parent().hide();
}
});
});
$('#completed-todo').click(function(e) {
e.preventDefault();
$(this).addClass('active');
$(activeStates).not(this).each(function() {
$(this).removeClass('active');
})
var completedItems = $('.todo-list input[type=checkbox]');
$(completedItems).each(function() {
if ($(this).is(':checked')) {
$(this).parent().show();
} else {
$(this).parent().hide();
}
})
});
});