From 708513039ab124cea933ce05b832caef32b1e34e Mon Sep 17 00:00:00 2001 From: iou1name Date: Thu, 20 Sep 2018 13:09:24 -0400 Subject: [PATCH] chat pane is hideable --- jinja2/base.html | 8 ++++++-- quest/jinja2/quest/quest.html | 3 ++- quest/static/quest.js | 12 ++++++++++++ set_session/views.py | 12 ++++++++---- static/base.css | 4 ++-- static/base.js | 14 +++++++------- 6 files changed, 37 insertions(+), 16 deletions(-) diff --git a/jinja2/base.html b/jinja2/base.html index 7608531..32d855f 100644 --- a/jinja2/base.html +++ b/jinja2/base.html @@ -5,17 +5,21 @@ {% block title %}{% endblock %} - Titivillus + {% block head %}{% endblock %}
-
+

Chat

{% autoescape false %} diff --git a/quest/static/quest.js b/quest/static/quest.js index aaf30c7..aa0aadc 100644 --- a/quest/static/quest.js +++ b/quest/static/quest.js @@ -247,3 +247,15 @@ function open_post(post_id) { } } } +function toggle_chat() { + if (document.getElementById('chatPane').style.display == 'flex') { + document.getElementById('chatPane').style.display = 'none'; + document.getElementById('questPane').style.width = '100%'; + toggle_cookie('hide_chat', 'on'); + } + else { + document.getElementById('chatPane').style.display = 'flex'; + document.getElementById('questPane').style.width = '70%'; + toggle_cookie('hide_chat', 'off'); + } +} diff --git a/set_session/views.py b/set_session/views.py index 5c9456f..22caf7e 100644 --- a/set_session/views.py +++ b/set_session/views.py @@ -8,8 +8,12 @@ def index(request): """ A simple API endpoint for setting certain values in the users session. """ - if request.POST.get('hide_header') == 'on': - request.session['hide_header'] = True - elif request.POST.get('hide_header') == 'off': - request.session['hide_header'] = False + for key, value in request.POST.items(): + if key not in ['hide_header', 'hide_chat']: + continue + if value == 'on': + request.session[key] = True + elif value == 'off': + request.session[key] = False + return HttpResponse('true') diff --git a/static/base.css b/static/base.css index 6ebffb1..373773d 100644 --- a/static/base.css +++ b/static/base.css @@ -1,5 +1,5 @@ :root { - --header-height: 1.6em; + --header-height: 1.25em; } body { @@ -32,7 +32,7 @@ body { } #headerHidden { - width: auto; + width: 1em; } #alerts { diff --git a/static/base.js b/static/base.js index 0ee36b3..77352a2 100644 --- a/static/base.js +++ b/static/base.js @@ -1,19 +1,19 @@ -function toggleHeaderCookie(state) { +function toggle_cookie(cookie, state) { let xhr = new XMLHttpRequest(); - xhr.open('POST', '{{ url("set_session:index") }}', true); + xhr.open('POST', set_session_url, true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.setRequestHeader('X-CSRFToken', '{{ csrf_token }}'); - xhr.send('hide_header=' + state); + xhr.setRequestHeader('X-CSRFToken', csrf_token); + xhr.send(cookie + '=' + state); } -function toggleHeader() { +function toggle_header() { if (document.getElementById('header').style.display == 'initial') { document.getElementById('header').style.display = 'none'; document.getElementById('headerHidden').style.display = 'initial'; - toggleHeaderCookie('on'); + toggle_cookie('hide_header', 'on'); } else { document.getElementById('header').style.display = 'initial'; document.getElementById('headerHidden').style.display = 'none'; - toggleHeaderCookie('off'); + toggle_cookie('hide_header', 'off'); } }