This repository has been archived by the owner on Nov 17, 2018. It is now read-only.
/
index.html
155 lines (143 loc) · 4.41 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en" manifest="cache.manifest">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width" />
<script src="js/jquery-1.6.3.min.js"></script>
<script src="js/qrcode.js"></script>
<script src="js/qrcanvas.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script>
var currentLoc;
$(function() {
// get location
if(navigator.geolocation){
var geocoder;
try {
geocoder = new google.maps.Geocoder();
} catch(e) {
}
if(geocoder) {
navigator.geolocation.getCurrentPosition(function(pos) {
var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results[1]) {
currentLoc = results[1].formatted_address;
}
});
});
}
}
// clicking checkbox toggles done state
$('#list li input[type=checkbox]').live('click', function(e) {
saveTodos();
});
// create new to do when clicking 'new'
$('#new').click(function() {
var title = prompt('To Do:');
createTodo(title);
return false;
});
// delete to do when clicking 'x'
$('.delete').live('click', function(e) {
$(e.target).parent('li').remove();
$('#delSound')[0].play();
saveTodos();
return false;
});
// clicking title shows qrcode
$('.title').live('click', function(e) {
var title = $(e.target).html();
var loc = $(e.target).parent().find('.loc').html();
$('#todos').hide();
append_qrcode(8, 'qrcode', location.href + '#' + JSON.stringify([title, loc]));
$('#todo').show();
$('.back').click(function() {
$('#qrcode').empty();
$('#todo').hide();
$('#todos').show();
return false;
});
return false;
});
loadTodos();
checkHash();
});
function checkHash() {
var hash = new String(location.hash).replace(/^#/, '')
if(hash != '') {
var todo = JSON.parse(hash)
createTodo(todo[0], false, todo[1]);
location.hash = '';
}
}
$(window).bind('hashchange', checkHash);
function buildTodo(title, done, loc) {
return "<li><input type='checkbox' " + (done ? "checked='checked'" : '') + "/> <a href='#' class='title'>" + title + "</a> <a href='#' class='delete'>x</a> <br/><span class='loc'>" + (loc || '') + "</span></li>";
}
function createTodo(title, done, loc) {
$('#list').append(buildTodo(title, !!done, loc || currentLoc));
saveTodos();
}
function loadTodos() {
if(localStorage['todos']) {
var todos = JSON.parse(localStorage['todos']);
for(var i=0; i<todos.length; i++) {
var todo = todos[i];
$('#list').append(buildTodo(todo.title, todo.done, todo.loc));
};
}
}
function saveTodos() {
var todos = []
var lis = $('#list li')
for(var i=0; i<lis.length; i++) {
var li = $(lis[i]);
todos.push({
title: li.find('.title').html(),
done: li.find('input').prop('checked'),
loc: li.find('.loc').html()
});
};
localStorage['todos'] = JSON.stringify(todos);
}
</script>
<style type="text/css">
#todos {
min-height: 1000px;
}
#list {
list-style: none;
margin: 0;
padding: 0;
}
li input {
vertical-align: middle;
}
.delete {
float: right;
}
.loc {
padding-left: 25px;
font-style: italic;
color: #999;
}
</style>
</head>
<body>
<img src="img/cat.jpg"/>
<div id="todos">
<ul id="list">
</ul>
<p><a href="#" id="new">new</a></p>
</div>
<div id="todo" style="display:none;">
<div id="qrcode"></div>
<a href="#" class="back">back</a>
</div>
<audio id="delSound" preload>
<source src="mp3/boom.mp3"/>
<source src="mp3/boom.ogg"/>
</audio>
</body>
</html>