-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
executable file
·81 lines (67 loc) · 2.83 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>HTML5 ToDo</title>
<meta name="viewport" content="height=device-height, width=device-width" />
<meta charset="utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/json.js"></script>
<script type="text/javascript">
Storage.prototype.setObject = function(key, value) {
this.setItem(key, JSON.stringify(value));
};
//
Storage.prototype.getObject = function(key) {
return eval('(' + this.getItem(key) + ')');
};
function update_tasks()
{
$('#task_list').html('');
var tasks = localStorage.getObject("tasks");
for (task in tasks)
{
var checked = tasks[task][1] ? "checked" : "";
$('#task_list').append('<li><label><input type="checkbox" name="'+task+'" '+checked+'/>'+tasks[task][0]+'</label></li>');
}
}
$(document).ready(function(){
update_tasks();
//save
$(':checkbox').live('click', function(){
return $('#task_form').submit();
});
$('#task_form').submit(function(e){
e.preventDefault();
var tasks = {};
$('#task_form :checkbox').each(function(){
var el = $(this);
tasks[el.attr('name')] = [el.parent().text(), el.is(':checked')];
});
localStorage.setObject("tasks", tasks);
});
//new
$('#task_new_form').submit(function(e){
e.preventDefault();
update_tasks();
var name = $(this).children('input').val();
if (name)
{
$(this).children('input').val('');
$('#task_list').append('<li><label><input type="checkbox" name="task'+($(':checkbox').length+1)+'" />'+name+'</label></li>');
}
$(this).children('input').blur(); //fix for iOS kb
$('#task_form').submit();
});
});
</script>
</head>
<body>
<h1>TODO:</h1>
<form id="task_form">
<ul id="task_list"></ul>
</form>
<form id="task_new_form">
<input type="text" name="new_task" placeholder="Enter new task...">
</form>
</body>
</html>