-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
135 lines (111 loc) · 3.08 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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Chat with me</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="/nowjs/now.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var scrollToLastMessage = function() {
var target = $("#msg > :last");
$('html,body').animate({
scrollTop: target.offset().top + target.height()
}, 250);
}
now.name = prompt("What is your name?", "");
now.email = prompt("What is your email?", "");
//now.logStuff("new user joined: " + now.name);
now.receiveMessage = function(name, hash, id, msg) {
// First, is this a server message?
if(id == 0 ){
var html = $("<p class='notice'></p>").html(msg);
} else {
// It's not a server message? Okay, fine.
var html = $("<p></p>").html("<img src='http://gravatar.com/avatar/" + hash + ".png?s=50' class='pic'> [<a href='#' class='user-direct' value='" + id + "' data-name='" + name + "'>" + name + "</a>] : " + msg);
}
$("#msg").append(html);
$("#msg").append(now.clientId);
scrollToLastMessage();
};
now.addUserToList = function(name, id) {
$("<li id='" + id + "'></li>").html("<a href='#' class='user-direct' value='" + id + "'>" + name + "</a>").appendTo($("#the-list"));
};
now.removeUserFromList = function(id) {
$("#" + id).remove();
};
$("#controls").submit(function(e) {
now.distributeMessage($("#text-input").val());
$("#text-input").val('');
e.preventDefault();
});
$(".user-direct").live('click', function() {
var name = $(this).attr('data-name'),
id = $(this).attr('value'),
msg = prompt('Send direct message to ' + name);
if(msg){
now.directMessage(id, msg);
}
});
});
</script>
<style type="text/css">
body {
font-family: 'Georgia';
}
#user-list {
background: #CCC;
position: fixed;
right: 10px;
top: 10px;
padding: 10px;
}
#controls {
width: 100%;
position: fixed;
bottom: 0;
left: 0;
padding: 10px;
background: #CCC;
height: 45px;
}
#text-input {
max-width: 920px;
width: 80%;
padding: 1em;
border-width: 0;
outline-width: 0;
font-size: 14px;
}
#spacer {
height: 25px;
}
.notice {
padding: 0.8em;
margin-bottom: 1em;
border: 2px solid;
background: #fff6bf;
color: #514721;
border-color: #ffd324;
font-style: italic;
}
</style>
</head>
<body>
<div id="container">
<header>
<h1>CHATBOT 9000</h1>
</header>
<div id="msg"></div>
<div id="spacer"></div>
<form id="controls" action="">
<input type="text" placeholder="Type here and press enter" id="text-input">
<input type="submit" value="Send" id="send">
</form>
<div id="user-list">
<h3>Online Users</h3>
<ul id="the-list">
</ul>
</div>
</div>
</body>
</html>