-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
95 lines (83 loc) · 3.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Alpha Pad</title>
<!-- Bootstrap -->
<link href="./css/bootstrap.min.css" rel="stylesheet">
<!--Custom -->
<link href="./css/style.css" rel="stylesheet">
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
</head>
<body>
<div class="container-fluid">
<div class="container">
<div class-"row">
<div class="col-md-3"></div>
<div class="col-md-5">
<div class="jumbotron main">
<h1 class="title text-center">To-do</h1>
<div id="post-here">
</div>
<div>
<p>
<input type="text" class="new-note" id="note" placeholder="Your note here"/>
<!-- <textarea rows="1" cols="30" class="new-note" id="note" placeholder="Your note here"></textarea> -->
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
var myDataRef = new Firebase('https://a580yx49ysr.firebaseio-demo.com/');
var childRef = myDataRef.push({}).key()
$('#note').keypress(function (e) {
if (e.keyCode == 13) {
var note = $('#note').val();
var isDone = "false";
childRef = myDataRef.push({note: note, isDone: isDone}).key();
$('#note').val('');
}
});
myDataRef.on('child_added', function(snapshot) {
var message = snapshot.val();
childRef = snapshot.key();
displayChatMessage(message.note, message.isDone, childRef);
});
function displayChatMessage(note, isDone, childRef) {
$('<p/>').text(note).attr('id', ''+childRef).appendTo($('#post-here'));
$('#'+childRef).css("cursor", "pointer");
if(isDone != "false") {
$('#'+childRef).css("text-decoration", "line-through");
} else {
$('#'+childRef).css("text-decoration", "");
}
$('#post-here')[0].scrollTop = $('#post-here')[0].scrollHeight;
};
$(this).click(function (e) {
if(event.target.id != "note" && event.target.id != "post-here") {
var ref = myDataRef.child(event.target.id);
ref.once("value", function(snapshot) {
var data = snapshot.val();
if(data.isDone == "false") {
$('#'+event.target.id).css("text-decoration", "line-through");
ref.update({note: data.note, isDone: "true"});
} else {
$('#'+event.target.id).css("text-decoration", "");
ref.update({note: data.note, isDone: "false"});
}
});
}
});
</script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="./js/jquery-2.1.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="./js/bootstrap.min.js"></script>
</html>