diff options
Diffstat (limited to 'app/Resources/static/themes/material/js/shortcuts')
-rw-r--r-- | app/Resources/static/themes/material/js/shortcuts/entry.js | 26 | ||||
-rw-r--r-- | app/Resources/static/themes/material/js/shortcuts/main.js | 76 |
2 files changed, 102 insertions, 0 deletions
diff --git a/app/Resources/static/themes/material/js/shortcuts/entry.js b/app/Resources/static/themes/material/js/shortcuts/entry.js new file mode 100644 index 00000000..e19800bd --- /dev/null +++ b/app/Resources/static/themes/material/js/shortcuts/entry.js | |||
@@ -0,0 +1,26 @@ | |||
1 | import Mousetrap from 'mousetrap'; | ||
2 | import $ from 'jquery'; | ||
3 | |||
4 | $(document).ready(() => { | ||
5 | if ($('#article').length > 0) { | ||
6 | /* open original article */ | ||
7 | Mousetrap.bind('o', () => { | ||
8 | $('ul.side-nav a.original i')[0].click(); | ||
9 | }); | ||
10 | |||
11 | /* mark as favorite */ | ||
12 | Mousetrap.bind('f', () => { | ||
13 | $('ul.side-nav a.favorite i')[0].click(); | ||
14 | }); | ||
15 | |||
16 | /* mark as read */ | ||
17 | Mousetrap.bind('a', () => { | ||
18 | $('ul.side-nav a.markasread i')[0].click(); | ||
19 | }); | ||
20 | |||
21 | /* delete */ | ||
22 | Mousetrap.bind('del', () => { | ||
23 | $('ul.side-nav a.delete i')[0].click(); | ||
24 | }); | ||
25 | } | ||
26 | }); | ||
diff --git a/app/Resources/static/themes/material/js/shortcuts/main.js b/app/Resources/static/themes/material/js/shortcuts/main.js new file mode 100644 index 00000000..ad4ca80a --- /dev/null +++ b/app/Resources/static/themes/material/js/shortcuts/main.js | |||
@@ -0,0 +1,76 @@ | |||
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 | } | ||
9 | |||
10 | $(document).ready(() => { | ||
11 | let cardIndex = 0; | ||
12 | const cardNumber = $('#content ul.data > li').length; | ||
13 | let card = $('#content ul.data > li')[cardIndex]; | ||
14 | const pagination = $('.pagination'); | ||
15 | |||
16 | /* Show nothing on quickstart */ | ||
17 | if ($('#content > div.quickstart').length > 0) { | ||
18 | return; | ||
19 | } | ||
20 | |||
21 | /* If we come from next page */ | ||
22 | if (window.location.hash === '#prev') { | ||
23 | cardIndex = cardNumber - 1; | ||
24 | card = $('ul.data > li')[cardIndex]; | ||
25 | } | ||
26 | |||
27 | /* Focus current card */ | ||
28 | toggleFocus(card); | ||
29 | |||
30 | /* Actions */ | ||
31 | Mousetrap.bind('g n', () => { | ||
32 | $('#nav-btn-add').trigger('click'); | ||
33 | return false; | ||
34 | }); | ||
35 | |||
36 | Mousetrap.bind('s', () => { | ||
37 | $('#nav-btn-search').trigger('click'); | ||
38 | return false; | ||
39 | }); | ||
40 | |||
41 | Mousetrap.bind('esc', () => { | ||
42 | $('.close').trigger('click'); | ||
43 | }); | ||
44 | |||
45 | /* Select right card. If there's a next page, go to next page */ | ||
46 | Mousetrap.bind('right', () => { | ||
47 | if (cardIndex >= 0 && cardIndex < cardNumber - 1) { | ||
48 | toggleFocus(card); | ||
49 | cardIndex += 1; | ||
50 | card = $('ul.data > li')[cardIndex]; | ||
51 | toggleFocus(card); | ||
52 | return; | ||
53 | } | ||
54 | if (pagination.length > 0 && pagination.find('li.next:not(.disabled)').length > 0 && cardIndex === cardNumber - 1) { | ||
55 | window.location.href = window.location.origin + $(pagination).find('li.next a').attr('href'); | ||
56 | } | ||
57 | }); | ||
58 | |||
59 | /* Select previous card. If there's a previous page, go to next page */ | ||
60 | Mousetrap.bind('left', () => { | ||
61 | if (cardIndex > 0 && cardIndex < cardNumber) { | ||
62 | toggleFocus(card); | ||
63 | cardIndex -= 1; | ||
64 | card = $('ul.data > li')[cardIndex]; | ||
65 | toggleFocus(card); | ||
66 | return; | ||
67 | } | ||
68 | if (pagination.length > 0 && $(pagination).find('li.prev:not(.disabled)').length > 0 && cardIndex === 0) { | ||
69 | window.location.href = `${window.location.origin + $(pagination).find('li.prev a').attr('href')}#prev`; | ||
70 | } | ||
71 | }); | ||
72 | |||
73 | Mousetrap.bind('enter', () => { | ||
74 | window.location.href = window.location.origin + $(card).find('span.card-title a').attr('href'); | ||
75 | }); | ||
76 | }); | ||