-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanipulate.js
More file actions
62 lines (49 loc) · 1.44 KB
/
manipulate.js
File metadata and controls
62 lines (49 loc) · 1.44 KB
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
$(document).ready(todoListTask);
function todoListTask(){
var $buttonAddTask = $('#buttonAddTask');
var $task = $('#task');
var index = 0;
var result = {
totalTask: 0,
numberCheckbox: 0
};
$task.trigger('focus');
$task.on('keypress', enterThenGetTask);
$buttonAddTask.on('click', getTask);
$('.enter-task').on('sendTask', receiveTaskThenDisplay);
function getTask(){
var task = $task.val();
if (task == ''){
alert('Please fill a new task!');
}
$task.val('');
$(this).trigger('sendTask',task);
};
function enterThenGetTask(event){
var isEnter = (event.which == 13);
if (isEnter) {
$buttonAddTask.trigger('click');
}
};
function receiveTaskThenDisplay(e, task){
index++;
$('ol').prepend("<li class = 'list-task'>"+"<input type = 'checkbox' id='box_"+index+"'></input>"+task+"<button id='buttonDelTask_"+index+"'> Del</button></li>");
var $buttonDelTask = $("#buttonDelTask_"+index+"");
var $boxCheck = $("#box_"+index+"");
// result.totalTask++;
// $(document).trigger('updateResult', [result]);
$buttonDelTask.on('click', deleteTask);
$boxCheck.on('change', handleCheckbox);
};
// var handleCheckbox(){
// var isChecked = $(this).is(':checked');
// if (isChecked) {
// result.numberCheckbox++;
// $(this).parent().addClass('done');
// }else{
// result.numberCheckbox--;
// $(this).parent().removeClass('done');
// }
// $(".display-task").trigger('updateResult', [result]);
// }
};