]>
Commit | Line | Data |
---|---|---|
5637a26e TC |
1 | import Mousetrap from 'mousetrap'; |
2 | import $ from 'jquery'; | |
3 | ||
4 | function toggleFocus(cardToToogleFocus) { | |
5 | if (cardToToogleFocus) { | |
6 | $(cardToToogleFocus).toggleClass('z-depth-4'); | |
7 | } | |
8 | } | |
5637a26e TC |
9 | |
10 | $(document).ready(() => { | |
78d6c309 S |
11 | const cards = $('#content').find('.card'); |
12 | const cardNumber = cards.length; | |
c9309923 | 13 | let cardIndex = 0; |
78d6c309 S |
14 | /* If we come from next page */ |
15 | if (window.location.hash === '#prev') { | |
16 | cardIndex = cardNumber - 1; | |
17 | } | |
18 | let card = cards[cardIndex]; | |
c9309923 | 19 | const pagination = $('.pagination'); |
5637a26e | 20 | |
10a1ffae TC |
21 | /* Show nothing on quickstart */ |
22 | if ($('#content > div.quickstart').length > 0) { | |
23 | return; | |
24 | } | |
25 | ||
a40029f9 NL |
26 | /* Show nothing on login/register page */ |
27 | if ($('#username').length > 0 || $('#fos_user_registration_form_username').length > 0) { | |
28 | return; | |
29 | } | |
30 | ||
18e1da62 TC |
31 | /* Show nothing on login/register page */ |
32 | if ($('#username').length > 0 || $('#fos_user_registration_form_username').length > 0) { | |
33 | return; | |
34 | } | |
35 | ||
5637a26e TC |
36 | /* Focus current card */ |
37 | toggleFocus(card); | |
38 | ||
39 | /* Actions */ | |
40 | Mousetrap.bind('g n', () => { | |
16ef7607 | 41 | $('#nav-btn-add').trigger('click'); |
995c2044 NL |
42 | return false; |
43 | }); | |
44 | ||
45 | Mousetrap.bind('s', () => { | |
46 | $('#nav-btn-search').trigger('click'); | |
47 | return false; | |
5637a26e | 48 | }); |
16ef7607 | 49 | |
5637a26e | 50 | Mousetrap.bind('esc', () => { |
16ef7607 | 51 | $('.close').trigger('click'); |
5637a26e TC |
52 | }); |
53 | ||
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) { | |
57 | toggleFocus(card); | |
58 | cardIndex += 1; | |
78d6c309 | 59 | card = cards[cardIndex]; |
5637a26e TC |
60 | toggleFocus(card); |
61 | return; | |
62 | } | |
c9309923 | 63 | if (pagination.length > 0 && pagination.find('li.next:not(.disabled)').length > 0 && cardIndex === cardNumber - 1) { |
5637a26e | 64 | window.location.href = window.location.origin + $(pagination).find('li.next a').attr('href'); |
5637a26e TC |
65 | } |
66 | }); | |
67 | ||
68 | /* Select previous card. If there's a previous page, go to next page */ | |
69 | Mousetrap.bind('left', () => { | |
70 | if (cardIndex > 0 && cardIndex < cardNumber) { | |
71 | toggleFocus(card); | |
72 | cardIndex -= 1; | |
78d6c309 | 73 | card = cards[cardIndex]; |
5637a26e TC |
74 | toggleFocus(card); |
75 | return; | |
76 | } | |
c9309923 | 77 | if (pagination.length > 0 && $(pagination).find('li.prev:not(.disabled)').length > 0 && cardIndex === 0) { |
5637a26e | 78 | window.location.href = `${window.location.origin + $(pagination).find('li.prev a').attr('href')}#prev`; |
5637a26e TC |
79 | } |
80 | }); | |
16ef7607 | 81 | |
5637a26e TC |
82 | Mousetrap.bind('enter', () => { |
83 | window.location.href = window.location.origin + $(card).find('span.card-title a').attr('href'); | |
84 | }); | |
16ef7607 | 85 | }); |