session remembers header hidden state
This commit is contained in:
parent
311b4723ea
commit
1529c77084
|
@ -59,6 +59,6 @@ def new_post(data):
|
|||
post = bleach.clean(post.strip())
|
||||
post = post.replace("\n", "<br />")
|
||||
data["post"] = [post]
|
||||
db.insert_quest_post(int(room), post, int(time.time()))
|
||||
db.insert_quest_post(room, post, int(time.time()))
|
||||
|
||||
emit("new_post", data, room=room)
|
||||
|
|
|
@ -5,25 +5,29 @@
|
|||
<link rel="stylesheet" type="text/css" href="/static/anonkun.css">
|
||||
<script>
|
||||
function toggleHeader() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
if (document.getElementById('header').style.display == 'initial') {
|
||||
document.getElementById('header').style.display = 'none';
|
||||
document.getElementById('headerHidden').style.display = 'initial';
|
||||
xhr.open('GET', '{{ url_for("views.set_session", hide_header="on") }}', true);
|
||||
}
|
||||
else {
|
||||
document.getElementById('header').style.display = 'initial';
|
||||
document.getElementById('headerHidden').style.display = 'none';
|
||||
xhr.open('GET', '{{ url_for("views.set_session", hide_header="off") }}', true);
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
</script>
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<ul id="header" class="header" style="display:initial;">
|
||||
<ul id="header" class="header" style="{% if session.get("hide_header") == True %}display:none;{% else %}display:initial;{% endif %}">
|
||||
<li><a onclick="toggleHeader();" href="javascript:void(0);">^</a></li>
|
||||
<li><a href="{{ url_for('views.index') }}">Home</a></li>
|
||||
{% block header %}{% endblock %}
|
||||
</ul>
|
||||
<ul id="headerHidden" class="header" style="display:none;">
|
||||
<ul id="headerHidden" class="header" style="{% if session.get("hide_header") == True %}display:initial;{% else %}display:none;{% endif %}">
|
||||
<li><a onclick="toggleHeader();" href="javascript:void(0);">^</a></li>
|
||||
</ul>
|
||||
<div id="content">{% block content %}{% endblock %} </div>
|
||||
|
|
|
@ -3,48 +3,48 @@
|
|||
{% block head %}
|
||||
<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 );
|
||||
var socket;
|
||||
var tid = setInterval( function () {
|
||||
if ( document.readyState !== 'complete' ) return;
|
||||
clearInterval( tid );
|
||||
|
||||
socket = io.connect('https://' + document.domain + ':' + location.port);
|
||||
socket.on('connect', function() {
|
||||
socket.emit('joined', {room: {{ room_id }}});
|
||||
});
|
||||
socket.on('message', function(data) {
|
||||
date = new Date(data.date * 1000);
|
||||
date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' ';
|
||||
date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds());
|
||||
|
||||
socket = io.connect('https://' + document.domain + ':' + location.port);
|
||||
socket.on('connect', function() {
|
||||
socket.emit('joined', {room: '{{ room_id }}' });
|
||||
});
|
||||
socket.on('message', function(data) {
|
||||
date = new Date(data.date * 1000);
|
||||
date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' ';
|
||||
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';
|
||||
|
||||
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';
|
||||
|
||||
mbox = document.getElementById('chatWindow');
|
||||
mbox.innerHTML = mbox.innerHTML + msg_str;
|
||||
mbox.scrollTop = mbox.scrollHeight;
|
||||
});
|
||||
socket.on('new_post', function(data) {
|
||||
qposts = document.getElementById('questPosts');
|
||||
qposts.innerHTML = qposts.innerHTML + '<div class="questPost">' + data.post + '</div>';
|
||||
});
|
||||
mtarea = document.getElementById('messageTextArea');
|
||||
mtarea.addEventListener('keypress', function(event) {
|
||||
if (event.key == 'Enter' && !event.shiftKey) {
|
||||
text = mtarea.value.trim();
|
||||
mtarea.value = '';
|
||||
if (text == '') { return; }
|
||||
socket.emit('message', {message: text, name: 'Anonymous', room: '{{ room_id }}'});
|
||||
}
|
||||
});
|
||||
}, 100 );
|
||||
mbox = document.getElementById('chatWindow');
|
||||
mbox.innerHTML = mbox.innerHTML + msg_str;
|
||||
mbox.scrollTop = mbox.scrollHeight;
|
||||
});
|
||||
socket.on('new_post', function(data) {
|
||||
qposts = document.getElementById('questPosts');
|
||||
qposts.innerHTML = qposts.innerHTML + '<div class="questPost">' + data.post + '</div>';
|
||||
});
|
||||
mtarea = document.getElementById('messageTextArea');
|
||||
mtarea.addEventListener('keypress', function(event) {
|
||||
if (event.key == 'Enter' && !event.shiftKey) {
|
||||
text = mtarea.value.trim();
|
||||
mtarea.value = '';
|
||||
if (text == '') { return; }
|
||||
socket.emit('message', {message: text, name: 'Anonymous', room: {{ room_id }}});
|
||||
}
|
||||
});
|
||||
}, 100 );
|
||||
</script>
|
||||
<script>
|
||||
function padToTwo(number) {
|
||||
if (number<=99) { number = ("0"+number).slice(-2); }
|
||||
return number;
|
||||
}
|
||||
function padToTwo(number) {
|
||||
if (number<=99) { number = ("0"+number).slice(-2); }
|
||||
return number;
|
||||
}
|
||||
</script>
|
||||
{% if session.get("user_id") == owner_id %}
|
||||
<script>
|
||||
|
@ -53,7 +53,7 @@
|
|||
text = qparea.value.trim();
|
||||
qparea.value = '';
|
||||
if (text == '') { return; }
|
||||
socket.emit('new_post', {post: text, room: '{{ room_id }}'});
|
||||
socket.emit('new_post', {post: text, room: {{ room_id }}});
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
|
|
13
views.py
13
views.py
|
@ -103,6 +103,19 @@ def edit_quest():
|
|||
return "lol"
|
||||
|
||||
|
||||
@views.route("/set_session")
|
||||
def set_session():
|
||||
"""
|
||||
Allows certain session values to be set by the client.
|
||||
"""
|
||||
hide_header = request.args.get("hide_header")
|
||||
if hide_header == "on":
|
||||
session["hide_header"] = True
|
||||
elif hide_header == "off":
|
||||
session["hide_header"] = False
|
||||
return ""
|
||||
|
||||
|
||||
@views.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user