forked from billgathen/i_resisted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi_resisted.html
93 lines (86 loc) · 3.07 KB
/
i_resisted.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>I Resisted</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
$(document).ready(function() {
$('#resisted').bind('click', function() { store('resisted') });
$('#failed').bind('click', function() { store('failed') });
$('#restart').bind('click', function() { clear(); });
update_counts();
show_history();
});
function store(action) {
localStorage.setItem('history', build_msg(action, localStorage["history"]));
$('#note').val('');
show_history();
update_counts();
}
function build_msg(action, existing_msg) {
if ( null == existing_msg ) {
existing_msg = '';
} else {
existing_msg = "<br/>" + existing_msg;
}
var note = $('#note').val();
var msg = 'I ' + action;
if ( note !== '' ) { msg = msg + ": " + note; }
return msg + existing_msg;
}
function show_history() {
$('#history').html(localStorage.getItem('history'));
}
function clear() {
localStorage.clear('history');
show_history();
update_counts();
}
function update_counts() {
var history = localStorage.getItem('history');
if (history) {
var resisted_count = "";
var failed_count = "";
var resisted = localStorage.getItem('history').match(/I resisted/g);
var failed = localStorage.getItem('history').match(/I failed/g);
resisted !== null ? resisted_count = resisted.length : resisted_count = "0";
failed !== null ? failed_count = failed.length : failed_count = "0";
} else {
resisted_count = "0";
failed_count = "0";
}
$('#resisted_count').text(resisted_count);
$('#failed_count').text(failed_count);
}
</script>
<style type="text/css">
#resisted_count, #failed_count { font-weight: 700; }
</style>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>I Resisted</h1>
</div>
<div data-role="content">
<div data-role="controlgroup" data-type="horizontal">
<a id="resisted" href="#" data-role="button" data-icon="check">I resisted :-)</a>
<a id="failed" href="#" data-role="button" data-icon="delete">I failed :-(</a>
</div>
<div>
Resisted Count: <span id="resisted_count"></span>
Failed Count: <span id="failed_count"></span>
</div>
<textarea id='note'></textarea>
<div id="history">
</div>
<a id="restart" href="#" data-role="button">Start fresh</a>
</div>
</div>
</body>
</html>