This repository was archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchat.html
More file actions
90 lines (77 loc) · 2.73 KB
/
chat.html
File metadata and controls
90 lines (77 loc) · 2.73 KB
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
{% extends "base.html" %}
{% block head %}
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
{% endblock %}
{% block header %}
<div class="docs-section">
<div class="container u-pull-center">
<div class="eight columns offset-by-two">
<h1>Slack Chat <i class="fa fa-slack fa-1x"></i> </h1>
<p>Allows anyone to send the DesignHub officers an anonymous message.
The message is posted on the officer private Slack channel. Give us some feedback, let us know how we're
doing, say "hey." And if we're online, we might answer.
Built with <i class="fa fa-heart"></i> by Ian</p>
</div>
</div>
</div>
{% endblock %}
{% block content %}
<div class="container">
<div class="row">
<div class="six columns">
<form>
<label for="message">Message</label>
<textarea class="u-full-width"
placeholder="Hey officers, here's what I think..."
id="message" name="message"></textarea>
</form>
<button class="button button-primary" onclick="sendMessage()">Send</button>
</div>
<div class="six columns" id="toggle">
<h4><i class="fa fa-comment"></i></h4>
<p id="reply">Message received. Let's see if someone answers back...</p>
</div>
</div>
</div>
<script type="text/javascript">
var token = '{{ token | safe}}';
var user;
document.getElementById('toggle').style.visibility = "hidden";
showToggle = function() {
document.getElementById('toggle').style.visibility = "visible";
};
sendMessage = function() {
var xhr = new XMLHttpRequest();
var path = "/sendmessage";
var message = document.getElementById('message').value;
path += "?message=" + message + '&user=' + user;
xhr.open("Post", path, true);
xhr.send();
showToggle();
document.getElementById('message').value = '';
};
onOpened = function() {
// Performed by channel callbacks
};
onClosed = function() {
// Performed by channel callbacks
};
onMessage = function(m) {
var payload = JSON.parse(m.data);
if (payload.user) {
user = payload.user;
console.log(user);
}
else if (payload.response){
document.getElementById('reply').innerHTML = payload.from + ': ' + payload.response;
showToggle();
}
};
channel = new goog.appengine.Channel(token);
socket = channel.open();
socket.onopen = onOpened;
socket.onmessage = onMessage;
socket.onerror = function() {};
socket.onclose = onClosed;
</script>
{% endblock %}