Enhance boost/fav toot with intercooler
Currently, this only works with CSRF protection turned off. Next job is to fix that.
This commit is contained in:
parent
02a20722fe
commit
8cdefb5e90
|
@ -47,7 +47,7 @@ MIDDLEWARE = [
|
|||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
#'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -27,7 +27,7 @@
|
|||
<link rel="stylesheet"
|
||||
href="{% static 'css/fork-awesome.min.css' %}">
|
||||
{% block page_scripts %}
|
||||
<script type="text/javascript" src="{% static 'js/zepto.min.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/intercooler.js' %}"></script>
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
@ -184,6 +184,31 @@
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr, settings) {
|
||||
function getCookie(name) {
|
||||
var cookieValue = null;
|
||||
if (document.cookie && document.cookie != '') {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = jQuery.trim(cookies[i]);
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
|
||||
// Only send the token to relative URLs i.e. locally.
|
||||
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
{% block page_scripts_inline %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{% if toot.visibility != 'private' and toot.visibility != 'direct' %}
|
||||
{% if toot.reblogged %}
|
||||
<span class="fa fa-retweet has-text-warning">
|
||||
<strong class="is-hidden-mobile" >Boosted</strong>
|
||||
{% else %}
|
||||
<span class="fa fa-retweet" >
|
||||
<span class="is-hidden-mobile" >Boost</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</span>
|
||||
{% endif %}
|
|
@ -0,0 +1,9 @@
|
|||
{% if toot.favourited %}
|
||||
<span class="fa fa-heart has-text-warning">
|
||||
<strong class="is-hidden-mobile" >Favorited</strong>
|
||||
{% else %}
|
||||
<span class="fa fa-heart">
|
||||
<span class="is-hidden-mobile" >Favorite</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</span>
|
|
@ -84,13 +84,15 @@
|
|||
{% if not confirm_page %}
|
||||
<nav class="level is-mobile">
|
||||
<div class="level-left">
|
||||
<a href="{% url "reply" toot.id %}" class="level-item">
|
||||
<a href="{% url "reply" toot.id %}" class="level-item"
|
||||
ic-post-to="{% url "reply" toot.id %}">
|
||||
<span class="fa fa-reply">
|
||||
<span class="is-hidden-mobile">Reply</span>
|
||||
</span>
|
||||
</a>
|
||||
{% if toot.visibility != 'private' and toot.visibility != 'direct' %}
|
||||
<a href="{% url "boost" toot.id %}" class="level-item">
|
||||
<a href="{% url "boost" toot.id %}" class="level-item"
|
||||
ic-post-to="{% url "boost" toot.id %}">
|
||||
{% if toot.reblogged %}
|
||||
<span class="fa fa-retweet has-text-warning">
|
||||
<strong class="is-hidden-mobile" >Boosted</strong>
|
||||
|
@ -102,7 +104,8 @@
|
|||
</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{% url "fav" toot.id %}" class="level-item">
|
||||
<a href="{% url "fav" toot.id %}" class="level-item"
|
||||
ic-post-to="{% url "fav" toot.id %}">
|
||||
{% if toot.favourited %}
|
||||
<span class="fa fa-heart has-text-warning">
|
||||
<strong class="is-hidden-mobile" >Favorited</strong>
|
||||
|
|
|
@ -546,7 +546,14 @@ def fav(request, id):
|
|||
mastodon.status_unfavourite(id)
|
||||
else:
|
||||
mastodon.status_favourite(id)
|
||||
return redirect(thread, id)
|
||||
if request.POST.get('ic-request'):
|
||||
toot['favourited'] = not toot['favourited']
|
||||
return render(request, 'intercooler/fav.html',
|
||||
{"toot": toot,
|
||||
'own_acct': request.session['user'],
|
||||
"preferences": account.preferences})
|
||||
else:
|
||||
return redirect(thread, id)
|
||||
else:
|
||||
return render(request, 'main/fav.html',
|
||||
{"toot": toot,
|
||||
|
@ -565,7 +572,14 @@ def boost(request, id):
|
|||
mastodon.status_unreblog(id)
|
||||
else:
|
||||
mastodon.status_reblog(id)
|
||||
return redirect(thread, id)
|
||||
if request.POST.get('ic-request'):
|
||||
toot['reblogged'] = not toot['reblogged']
|
||||
return render(request, 'intercooler/boost.html',
|
||||
{"toot": toot,
|
||||
'own_acct': request.session['user'],
|
||||
"preferences": account.preferences})
|
||||
else:
|
||||
return redirect(thread, id)
|
||||
else:
|
||||
return render(request, 'main/boost.html',
|
||||
{"toot": toot,
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"bulmaswatch": "^0.6.2",
|
||||
"fork-awesome": "^1.1.0",
|
||||
"intercooler": "^1.2.1",
|
||||
"jquery": "^3.3.1",
|
||||
"mousetrap": "^1.6.2",
|
||||
"zepto": "^1.2.0"
|
||||
}
|
||||
|
|
|
@ -18,6 +18,10 @@ intercooler@^1.2.1:
|
|||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/intercooler/-/intercooler-1.2.1.tgz#50e9727ef2643ef7d5130c8e58f2af78098aa01f"
|
||||
|
||||
jquery@^3.3.1:
|
||||
version "3.3.1"
|
||||
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.3.1.tgz#958ce29e81c9790f31be7792df5d4d95fc57fbca"
|
||||
|
||||
mousetrap@^1.6.2:
|
||||
version "1.6.2"
|
||||
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.2.tgz#caadd9cf886db0986fb2fee59a82f6bd37527587"
|
||||
|
|
Loading…
Reference in New Issue