mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
more keyboard shortcuts
This commit is contained in:
parent
cdc685ba8a
commit
70768dadff
3 changed files with 26 additions and 10 deletions
|
@ -366,29 +366,45 @@ var currentPost;
|
||||||
function setupKeyboardShortcuts() {
|
function setupKeyboardShortcuts() {
|
||||||
document.addEventListener('keydown', function(event) {
|
document.addEventListener('keydown', function(event) {
|
||||||
if (document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {
|
if (document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {
|
||||||
|
var didSomething = false;
|
||||||
if (event.key === 'a') {
|
if (event.key === 'a') {
|
||||||
if(currentPost) {
|
if(currentPost) {
|
||||||
currentPost.querySelector('.upvote_button').click();
|
currentPost.querySelector('.upvote_button').click();
|
||||||
|
didSomething = true;
|
||||||
}
|
}
|
||||||
} else if (event.key === 'z') {
|
} else if (event.key === 'z') {
|
||||||
if(currentPost) {
|
if(currentPost) {
|
||||||
currentPost.querySelector('.downvote_button').click();
|
currentPost.querySelector('.downvote_button').click();
|
||||||
|
didSomething = true;
|
||||||
|
}
|
||||||
|
} else if (event.key === 'x') {
|
||||||
|
if(currentPost) {
|
||||||
|
currentPost.querySelector('.preview_image').click();
|
||||||
|
didSomething = true;
|
||||||
|
}
|
||||||
|
} else if (event.key === 'l') {
|
||||||
|
if(currentPost) {
|
||||||
|
currentPost.querySelector('.post_link').click();
|
||||||
|
didSomething = true;
|
||||||
}
|
}
|
||||||
} else if (event.key === 'Enter') {
|
} else if (event.key === 'Enter') {
|
||||||
if(document.activeElement.classList.contains('downvote_button') || document.activeElement.classList.contains('upvote_button')) {
|
if(document.activeElement.classList.contains('downvote_button') || document.activeElement.classList.contains('upvote_button')) {
|
||||||
document.activeElement.click();
|
document.activeElement.click();
|
||||||
|
didSomething = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
if(didSomething) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const postTeasers = document.querySelectorAll('.post_teaser, .comments .comment');
|
const votableElements = document.querySelectorAll('.post_teaser, .comments .comment, .post_type_image, .post_type_normal');
|
||||||
postTeasers.forEach(postTeaser => {
|
votableElements.forEach(votable => {
|
||||||
postTeaser.addEventListener('mouseover', event => {
|
votable.addEventListener('mouseover', event => {
|
||||||
currentPost = event.currentTarget;
|
currentPost = event.currentTarget;
|
||||||
});
|
});
|
||||||
postTeaser.addEventListener('mouseout', event => {
|
votable.addEventListener('mouseout', event => {
|
||||||
currentPost = null;
|
currentPost = null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
</h1>
|
</h1>
|
||||||
{% if post.type == POST_TYPE_LINK and post.image_id and not (post.url and 'youtube.com' in post.url) %}
|
{% if post.type == POST_TYPE_LINK and post.image_id and not (post.url and 'youtube.com' in post.url) %}
|
||||||
<div class="url_thumbnail">
|
<div class="url_thumbnail">
|
||||||
<a href="{{ post.url }}" target="_blank"><img src="{{ post.image.thumbnail_url() }}" alt="{{ post.image.alt_text }}"
|
<a href="{{ post.url }}" target="_blank" rel="nofollow ugc" class="post_link"><img src="{{ post.image.thumbnail_url() }}" alt="{{ post.image.alt_text }}"
|
||||||
width="{{ post.image.thumbnail_width }}" height="{{ post.image.thumbnail_height }}" /></a>
|
width="{{ post.image.thumbnail_width }}" height="{{ post.image.thumbnail_height }}" /></a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
{% if post.edited_at %} edited {{ moment(post.edited_at).fromNow() }}{% endif %}</small>
|
{% if post.edited_at %} edited {{ moment(post.edited_at).fromNow() }}{% endif %}</small>
|
||||||
</p>
|
</p>
|
||||||
{% if post.type == POST_TYPE_LINK %}
|
{% if post.type == POST_TYPE_LINK %}
|
||||||
<p><small><a href="{{ post.url }}" rel="nofollow ugc" target="_blank">{{ post.url|shorten_url }}
|
<p><small><a href="{{ post.url }}" rel="nofollow ugc" target="_blank" class="post_link">{{ post.url|shorten_url }}
|
||||||
<img src="/static/images/external_link_black.svg" class="external_link_icon" alt="External link" /></a>
|
<img src="/static/images/external_link_black.svg" class="external_link_icon" alt="External link" /></a>
|
||||||
</small></p>
|
</small></p>
|
||||||
{% if 'youtube.com' in post.url %}
|
{% if 'youtube.com' in post.url %}
|
||||||
|
@ -89,12 +89,12 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif post.type == POST_TYPE_IMAGE %}
|
{% elif post.type == POST_TYPE_IMAGE %}
|
||||||
<div class="post_image">
|
<div class="post_image">
|
||||||
<a href="{{ post.image.view_url() }}" target="_blank"><img src="{{ post.image.view_url() }}" alt="{{ post.image.alt_text }}"
|
<a href="{{ post.image.view_url() }}" target="_blank" class="post_link" rel="nofollow ugc"><img src="{{ post.image.view_url() }}" alt="{{ post.image.alt_text }}"
|
||||||
width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
|
width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if post.image_id and not (post.url and 'youtube.com' in post.url) %}
|
{% if post.image_id and not (post.url and 'youtube.com' in post.url) %}
|
||||||
<a href="{{ post.image.view_url() }}" target="_blank"><img src="{{ post.image.thumbnail_url() }}" alt="{{ post.image.alt_text }}"
|
<a href="{{ post.image.view_url() }}" target="_blank" class="post_link" rel="nofollow ugc"><img src="{{ post.image.thumbnail_url() }}" alt="{{ post.image.alt_text }}"
|
||||||
width="{{ post.image.thumbnail_width }}" height="{{ post.image.thumbnail_height }}" /></a>
|
width="{{ post.image.thumbnail_width }}" height="{{ post.image.thumbnail_height }}" /></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<div class="thumbnail">
|
<div class="thumbnail">
|
||||||
{% if post.type == POST_TYPE_LINK %}
|
{% if post.type == POST_TYPE_LINK %}
|
||||||
<a href="{{ post.url }}" rel="nofollow ugc" target="_blank" aria-label="{{ _('Read article') }}"><img src="{{ post.image.thumbnail_url() }}"
|
<a href="{{ post.url }}" rel="nofollow ugc" target="_blank" aria-label="{{ _('Read article') }}"><img src="{{ post.image.thumbnail_url() }}"
|
||||||
alt="{{ post.image.alt_text if post.image.alt_text else '' }}" height="50" /></a>
|
alt="{{ post.image.alt_text if post.image.alt_text else '' }}" height="50" class="post_link" /></a>
|
||||||
{% elif post.type == POST_TYPE_IMAGE %}
|
{% elif post.type == POST_TYPE_IMAGE %}
|
||||||
{% if post.image_id %}
|
{% if post.image_id %}
|
||||||
<a href="{{ post.image.view_url() }}" rel="nofollow ugc" target="_blank"><img src="{{ post.image.thumbnail_url() }}"
|
<a href="{{ post.image.view_url() }}" rel="nofollow ugc" target="_blank"><img src="{{ post.image.thumbnail_url() }}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue