-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.htm
166 lines (130 loc) · 4.59 KB
/
index.htm
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
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
nav {
background-color: #10afec !important;
margin-bottom: 6px;
}
.card-action{
padding: 8x !important;
}
.card-action > a{
/*float : right;*/
font-size: smaller;
}
.date-footer{
color: blue;
}
.block{
display: inline-block;
}
</style>
</head>
<body>
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo">TODO <time></time></a>
</div>
</nav>
<div class="row">
<div class="col s10 m11">
<input type="text" id="todoText" placeholder="Add your item" />
</div>
<div class="col s2 m1">
<a class="btn-floating btn-large waves-effect waves-light red"><i class="material-icons">add</i></a>
</div>
</div>
<div class="row">
</div>
<div class="row" id="list">
<!--<div class="col s12 m6">
<div class="card horizontal col s12 m12">
<div class="card-stacked">
<div class="card-content">
<p>
<input type="checkbox" id="test5" />
<label for="test5">this is the new todo</label>
</p>
</div>
<div class="card-action">
<a href="#">2 Years Ago</a>
</div>
</div>
</div>
</div>-->
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.4.0/firebase.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.0/moment.min.js"></script>
<script id="entry-template" type="text/x-handlebars-template">
<div class="col s12 m12 ">
<div class="card horizontal col s12 m12 hoverable">
<div class="card-stacked">
<div class="card-content">
<div class="">
<p>
<input type="checkbox" id="{{itemText}}id" {{isDone}} />
<label for="{{itemText}}id">{{itemText}}</label>
</p>
</div>
</div>
<div class="card-action">
<a href="#">Added On: <span class="date-footer">{{timestamp}}</span></a>
<a href="#">Updated On: <span class="date-footer">{{timestamp}}</span></a>
<a class="btn-floating waves-effect waves-light orange"><i class="material-icons">edit</i></a>
<a class="btn-floating waves-effect waves-light red"><i class="material-icons">delete</i></a>
</div>
</div>
</div>
</div>
</script>
<script>
$(function(){
var config = {
apiKey: "AIzaSyC5BwDqeg3mjRkj7U9GGfO-y256xt2IEgs",
authDomain: "hello-firebase-bf004.firebaseapp.com",
databaseURL: "https://hello-firebase-bf004.firebaseio.com",
storageBucket: "hello-firebase-bf004.appspot.com",
messagingSenderId: "1059567983283"
};
var dbApp = firebase.initializeApp(config);
var dbList = dbApp.database().ref("todo");
var source = $("#entry-template").html();
var template = Handlebars.compile(source);
$("a").click(function(){
debugger;
var text = $('#todoText').val();
if(text.length != 0){
addItem(text);
}
});
dbList.on('child_added', function(data) {
debugger;
showItem(data.val().itemText,data.val().timestamp,data.val().isDone);
});
function showItem(text, timestamp, isDone){
var context = { itemText : text, timestamp: moment(timestamp, 'X').format('DD-MMM-YYYY hh:mm:ss'), isDone: isDone == true ? 'checked' : ''};
var html = template(context);
$('#list').prepend(html);
}
function addItem(text){
var context = { itemText : text, timestamp: moment().format("X"), isDone: false};
dbList.push().set(context);
}
});
</script>
</body>
</html>
</html>