2018-06-18 22:13:49 -04:00
|
|
|
{% extends "base.html" %}
|
|
|
|
{% block title %}{{ quest_title }}{% endblock %}
|
|
|
|
{% block head %}
|
2018-06-14 19:15:51 -04:00
|
|
|
<script type="text/javascript" src="/static/socket.io.slim.js"></script>
|
|
|
|
<script>
|
|
|
|
var socket;
|
|
|
|
var tid = setInterval( function () {
|
|
|
|
if ( document.readyState !== 'complete' ) return;
|
|
|
|
clearInterval( tid );
|
|
|
|
|
|
|
|
socket = io.connect('https://' + document.domain + ':' + location.port + '/chat');
|
|
|
|
socket.on('connect', function() {
|
2018-06-16 03:17:00 -04:00
|
|
|
socket.emit('joined', {room: '{{ room_id }}' });
|
2018-06-14 19:15:51 -04:00
|
|
|
});
|
|
|
|
socket.on('message', function(data) {
|
|
|
|
date = new Date(data.date * 1000);
|
2018-06-17 21:10:41 -04:00
|
|
|
date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' ';
|
2018-06-14 19:15:51 -04:00
|
|
|
date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds());
|
|
|
|
|
|
|
|
msg_str = '<div class="messageHeader">\n<span class="messageName">' + data.name + '</span> ';
|
|
|
|
msg_str += '<span class="messageDate">' + date_str + '</span>\n</div>\n';
|
|
|
|
msg_str += '<div class="message">' + data.message + '</div>\n';
|
|
|
|
|
2018-06-14 22:09:14 -04:00
|
|
|
mbox = document.getElementById('chatWindow');
|
2018-06-14 19:15:51 -04:00
|
|
|
mbox.innerHTML = mbox.innerHTML + msg_str;
|
|
|
|
mbox.scrollTop = mbox.scrollHeight;
|
|
|
|
});
|
2018-06-14 22:09:14 -04:00
|
|
|
mtarea = document.getElementById('messageTextarea');
|
|
|
|
mtarea.addEventListener('keypress', function(event) {
|
2018-06-17 18:09:11 -04:00
|
|
|
if (event.key == 'Enter' && !event.shiftKey) {
|
|
|
|
text = mtarea.value.trim();
|
2018-06-14 22:09:14 -04:00
|
|
|
mtarea.value = '';
|
2018-06-17 18:09:11 -04:00
|
|
|
if (text == '') { return; }
|
2018-06-16 03:17:00 -04:00
|
|
|
socket.emit('message', {message: text, name: 'Anonymous', room: '{{ room_id }}'});
|
2018-06-14 19:15:51 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 100 );
|
|
|
|
|
|
|
|
function padToTwo(number) {
|
|
|
|
if (number<=99) { number = ("0"+number).slice(-2); }
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
</script>
|
2018-06-18 22:13:49 -04:00
|
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
|
|
<div id="questContainer">
|
|
|
|
<div id="questBody">
|
|
|
|
<h1>{{ quest_title }}</h1>
|
2018-06-18 00:17:56 -04:00
|
|
|
{% autoescape false %}
|
2018-06-18 22:13:49 -04:00
|
|
|
{{ quest_body }}
|
2018-06-18 00:17:56 -04:00
|
|
|
{% endautoescape %}
|
2018-06-14 22:09:14 -04:00
|
|
|
</div>
|
2018-06-18 22:13:49 -04:00
|
|
|
<div id="chatPane">
|
|
|
|
<h1>Chat</h1>
|
|
|
|
<div id="chatWindow">
|
|
|
|
{% autoescape false %}
|
|
|
|
{% for message in messages %}
|
|
|
|
<div class="message">
|
|
|
|
<div class="messageHeader">
|
|
|
|
<span class="messageName">{{ message[1] }}</span> <span class="messageDate">{{ message[3] | strftime }}</span>
|
|
|
|
</div>
|
|
|
|
<div class="messageMessage">{{ message[4] }}</div>
|
|
|
|
</div>
|
|
|
|
{% endfor %}
|
|
|
|
{% endautoescape %}
|
|
|
|
</div>
|
|
|
|
<div id="messageBox"><textarea id="messageTextarea"></textarea></div>
|
2018-06-14 19:15:51 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-06-18 22:13:49 -04:00
|
|
|
{% endblock %}
|