aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes/material/js/shortcuts/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/Resources/static/themes/material/js/shortcuts/main.js')
-rw-r--r--app/Resources/static/themes/material/js/shortcuts/main.js74
1 files changed, 66 insertions, 8 deletions
diff --git a/app/Resources/static/themes/material/js/shortcuts/main.js b/app/Resources/static/themes/material/js/shortcuts/main.js
index ccd3c92d..62b7ec64 100644
--- a/app/Resources/static/themes/material/js/shortcuts/main.js
+++ b/app/Resources/static/themes/material/js/shortcuts/main.js
@@ -1,13 +1,71 @@
1/* Actions */ 1import Mousetrap from 'mousetrap';
2Mousetrap.bind('g n', () => { 2import $ from 'jquery';
3
4function toggleFocus(cardToToogleFocus) {
5 if (cardToToogleFocus) {
6 $(cardToToogleFocus).toggleClass('z-depth-4');
7 }
8}
9let card;
10let cardIndex;
11let cardNumber;
12let pagination;
13
14$(document).ready(() => {
15 cardIndex = 0;
16 cardNumber = $('#content ul.data > li').length;
17 card = $('#content ul.data > li')[cardIndex];
18 pagination = $('.pagination');
19
20 /* If we come from next page */
21 if (window.location.hash === '#prev') {
22 cardIndex = cardNumber - 1;
23 card = $('ul.data > li')[cardIndex];
24 }
25
26 /* Focus current card */
27 toggleFocus(card);
28
29 /* Actions */
30 Mousetrap.bind('g n', () => {
3 $('#nav-btn-add').trigger('click'); 31 $('#nav-btn-add').trigger('click');
4}); 32 });
5 33
6Mousetrap.bind('esc', () => { 34 Mousetrap.bind('esc', () => {
7 $('.close').trigger('click'); 35 $('.close').trigger('click');
8}); 36 });
37
38 /* Select right card. If there's a next page, go to next page */
39 Mousetrap.bind('right', () => {
40 if (cardIndex >= 0 && cardIndex < cardNumber - 1) {
41 toggleFocus(card);
42 cardIndex += 1;
43 card = $('ul.data > li')[cardIndex];
44 toggleFocus(card);
45 return;
46 }
47 if (pagination != null && pagination.find('li.next') && cardIndex === cardNumber - 1) {
48 window.location.href = window.location.origin + $(pagination).find('li.next a').attr('href');
49 return;
50 }
51 });
52
53 /* Select previous card. If there's a previous page, go to next page */
54 Mousetrap.bind('left', () => {
55 if (cardIndex > 0 && cardIndex < cardNumber) {
56 toggleFocus(card);
57 cardIndex -= 1;
58 card = $('ul.data > li')[cardIndex];
59 toggleFocus(card);
60 return;
61 }
62 if (pagination !== null && $(pagination).find('li.prev') && cardIndex === 0) {
63 window.location.href = `${window.location.origin + $(pagination).find('li.prev a').attr('href')}#prev`;
64 return;
65 }
66 });
9 67
10// Display the first element of the current view 68 Mousetrap.bind('enter', () => {
11Mousetrap.bind('right', () => { 69 window.location.href = window.location.origin + $(card).find('span.card-title a').attr('href');
12 $('ul.data li:first-child span.dot-ellipsis a')[0].click(); 70 });
13}); 71});