mirror of
https://gitlab.com/brutaldon/brutaldon
synced 2025-06-05 21:49:32 +02:00
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:
@@ -47,7 +47,7 @@ MIDDLEWARE = [
|
|||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
#'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
2
brutaldon/static/js/jquery.min.js
vendored
Normal file
2
brutaldon/static/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
2
brutaldon/static/js/zepto.min.js
vendored
2
brutaldon/static/js/zepto.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -27,7 +27,7 @@
|
|||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
href="{% static 'css/fork-awesome.min.css' %}">
|
href="{% static 'css/fork-awesome.min.css' %}">
|
||||||
{% block page_scripts %}
|
{% 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>
|
<script type="text/javascript" src="{% static 'js/intercooler.js' %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% endif %}
|
{% 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>
|
</script>
|
||||||
{% block page_scripts_inline %}
|
{% block page_scripts_inline %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
11
brutaldon/templates/intercooler/boost.html
Normal file
11
brutaldon/templates/intercooler/boost.html
Normal file
@@ -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 %}
|
9
brutaldon/templates/intercooler/fav.html
Normal file
9
brutaldon/templates/intercooler/fav.html
Normal file
@@ -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 %}
|
{% if not confirm_page %}
|
||||||
<nav class="level is-mobile">
|
<nav class="level is-mobile">
|
||||||
<div class="level-left">
|
<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="fa fa-reply">
|
||||||
<span class="is-hidden-mobile">Reply</span>
|
<span class="is-hidden-mobile">Reply</span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
{% if toot.visibility != 'private' and toot.visibility != 'direct' %}
|
{% 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 %}
|
{% if toot.reblogged %}
|
||||||
<span class="fa fa-retweet has-text-warning">
|
<span class="fa fa-retweet has-text-warning">
|
||||||
<strong class="is-hidden-mobile" >Boosted</strong>
|
<strong class="is-hidden-mobile" >Boosted</strong>
|
||||||
@@ -102,7 +104,8 @@
|
|||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% 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 %}
|
{% if toot.favourited %}
|
||||||
<span class="fa fa-heart has-text-warning">
|
<span class="fa fa-heart has-text-warning">
|
||||||
<strong class="is-hidden-mobile" >Favorited</strong>
|
<strong class="is-hidden-mobile" >Favorited</strong>
|
||||||
|
@@ -546,6 +546,13 @@ def fav(request, id):
|
|||||||
mastodon.status_unfavourite(id)
|
mastodon.status_unfavourite(id)
|
||||||
else:
|
else:
|
||||||
mastodon.status_favourite(id)
|
mastodon.status_favourite(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)
|
return redirect(thread, id)
|
||||||
else:
|
else:
|
||||||
return render(request, 'main/fav.html',
|
return render(request, 'main/fav.html',
|
||||||
@@ -565,6 +572,13 @@ def boost(request, id):
|
|||||||
mastodon.status_unreblog(id)
|
mastodon.status_unreblog(id)
|
||||||
else:
|
else:
|
||||||
mastodon.status_reblog(id)
|
mastodon.status_reblog(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)
|
return redirect(thread, id)
|
||||||
else:
|
else:
|
||||||
return render(request, 'main/boost.html',
|
return render(request, 'main/boost.html',
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
"bulmaswatch": "^0.6.2",
|
"bulmaswatch": "^0.6.2",
|
||||||
"fork-awesome": "^1.1.0",
|
"fork-awesome": "^1.1.0",
|
||||||
"intercooler": "^1.2.1",
|
"intercooler": "^1.2.1",
|
||||||
|
"jquery": "^3.3.1",
|
||||||
"mousetrap": "^1.6.2",
|
"mousetrap": "^1.6.2",
|
||||||
"zepto": "^1.2.0"
|
"zepto": "^1.2.0"
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,10 @@ intercooler@^1.2.1:
|
|||||||
version "1.2.1"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/intercooler/-/intercooler-1.2.1.tgz#50e9727ef2643ef7d5130c8e58f2af78098aa01f"
|
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:
|
mousetrap@^1.6.2:
|
||||||
version "1.6.2"
|
version "1.6.2"
|
||||||
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.2.tgz#caadd9cf886db0986fb2fee59a82f6bd37527587"
|
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.2.tgz#caadd9cf886db0986fb2fee59a82f6bd37527587"
|
||||||
|
Reference in New Issue
Block a user