]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/material/js/shortcuts/main.js
1 import Mousetrap
from 'mousetrap';
2 import $ from 'jquery';
4 function toggleFocus(cardToToogleFocus
) {
5 if (cardToToogleFocus
) {
6 $(cardToToogleFocus
).toggleClass('z-depth-4');
10 $(document
).ready(() => {
11 const cards
= $('#content').find('.card');
12 const cardNumber
= cards
.length
;
14 /* If we come from next page */
15 if (window
.location
.hash
=== '#prev') {
16 cardIndex
= cardNumber
- 1;
18 let card
= cards
[cardIndex
];
19 const pagination
= $('.pagination');
21 /* Show nothing on quickstart */
22 if ($('#content > div.quickstart').length
> 0) {
26 /* Show nothing on login/register page */
27 if ($('#username').length
> 0 || $('#fos_user_registration_form_username').length
> 0) {
31 /* Show nothing on login/register page */
32 if ($('#username').length
> 0 || $('#fos_user_registration_form_username').length
> 0) {
36 /* Focus current card */
40 Mousetrap
.bind('g n', () => {
41 $('#nav-btn-add').trigger('click');
45 Mousetrap
.bind('s', () => {
46 $('#nav-btn-search').trigger('click');
50 Mousetrap
.bind('esc', () => {
51 $('.close').trigger('click');
54 /* Select right card. If there's a next page, go to next page */
55 Mousetrap
.bind('right', () => {
56 if (cardIndex
>= 0 && cardIndex
< cardNumber
- 1) {
59 card
= cards
[cardIndex
];
63 if (pagination
.length
> 0 && pagination
.find('li.next:not(.disabled)').length
> 0 && cardIndex
=== cardNumber
- 1) {
64 window
.location
.href
= window
.location
.origin
+ $(pagination
).find('li.next a').attr('href');
68 /* Select previous card. If there's a previous page, go to next page */
69 Mousetrap
.bind('left', () => {
70 if (cardIndex
> 0 && cardIndex
< cardNumber
) {
73 card
= cards
[cardIndex
];
77 if (pagination
.length
> 0 && $(pagination
).find('li.prev:not(.disabled)').length
> 0 && cardIndex
=== 0) {
78 window
.location
.href
= `${window.location.origin + $(pagination).find('li.prev a').attr('href')}#prev`;
82 Mousetrap
.bind('enter', () => {
83 window
.location
.href
= window
.location
.origin
+ $(card
).find('span.card-title a').attr('href');