aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes/material/js
diff options
context:
space:
mode:
Diffstat (limited to 'app/Resources/static/themes/material/js')
-rwxr-xr-xapp/Resources/static/themes/material/js/init.js19
-rw-r--r--app/Resources/static/themes/material/js/shortcuts/entry.js26
-rw-r--r--app/Resources/static/themes/material/js/shortcuts/main.js75
3 files changed, 116 insertions, 4 deletions
diff --git a/app/Resources/static/themes/material/js/init.js b/app/Resources/static/themes/material/js/init.js
index a68269e0..0b2832c0 100755
--- a/app/Resources/static/themes/material/js/init.js
+++ b/app/Resources/static/themes/material/js/init.js
@@ -1,10 +1,21 @@
1/* jQuery */
2import $ from 'jquery';
3
4/* Annotations */
5import annotator from 'annotator';
6
7/* Tools */
1import { savePercent, retrievePercent, initFilters, initExport } from '../../_global/js/tools'; 8import { savePercent, retrievePercent, initFilters, initExport } from '../../_global/js/tools';
2 9
3const $ = require('jquery'); 10/* Import shortcuts */
11import './shortcuts/main';
12import './shortcuts/entry';
13import '../../_global/js/shortcuts/main';
14import '../../_global/js/shortcuts/entry';
4 15
5global.jQuery = $;
6require('materialize'); // eslint-disable-line 16require('materialize'); // eslint-disable-line
7const annotator = require('annotator'); 17
18global.jQuery = $;
8 19
9$(document).ready(() => { 20$(document).ready(() => {
10 // sideNav 21 // sideNav
@@ -44,7 +55,7 @@ $(document).ready(() => {
44 $('.nav-panels .action').hide(100); 55 $('.nav-panels .action').hide(100);
45 $('.nav-panel-menu').addClass('hidden'); 56 $('.nav-panel-menu').addClass('hidden');
46 $('.nav-panels').css('background', 'white'); 57 $('.nav-panels').css('background', 'white');
47 $('#searchfield').focus(); 58 $('#search_entry_term').focus();
48 return false; 59 return false;
49 }); 60 });
50 $('.close').on('click', () => { 61 $('.close').on('click', () => {
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 @@
1import Mousetrap from 'mousetrap';
2import $ 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..0a2d2a69
--- /dev/null
+++ b/app/Resources/static/themes/material/js/shortcuts/main.js
@@ -0,0 +1,75 @@
1import Mousetrap from 'mousetrap';
2import $ from 'jquery';
3
4function toggleFocus(cardToToogleFocus) {
5 if (cardToToogleFocus) {
6 $(cardToToogleFocus).toggleClass('z-depth-4');
7 }
8}
9
10$(document).ready(() => {
11 const cards = $('#content').find('.card');
12 const cardNumber = cards.length;
13 let cardIndex = 0;
14 /* If we come from next page */
15 if (window.location.hash === '#prev') {
16 cardIndex = cardNumber - 1;
17 }
18 let card = cards[cardIndex];
19 const pagination = $('.pagination');
20
21 /* Show nothing on quickstart */
22 if ($('#content > div.quickstart').length > 0) {
23 return;
24 }
25
26 /* Focus current card */
27 toggleFocus(card);
28
29 /* Actions */
30 Mousetrap.bind('g n', () => {
31 $('#nav-btn-add').trigger('click');
32 return false;
33 });
34
35 Mousetrap.bind('s', () => {
36 $('#nav-btn-search').trigger('click');
37 return false;
38 });
39
40 Mousetrap.bind('esc', () => {
41 $('.close').trigger('click');
42 });
43
44 /* Select right card. If there's a next page, go to next page */
45 Mousetrap.bind('right', () => {
46 if (cardIndex >= 0 && cardIndex < cardNumber - 1) {
47 toggleFocus(card);
48 cardIndex += 1;
49 card = cards[cardIndex];
50 toggleFocus(card);
51 return;
52 }
53 if (pagination.length > 0 && pagination.find('li.next:not(.disabled)').length > 0 && cardIndex === cardNumber - 1) {
54 window.location.href = window.location.origin + $(pagination).find('li.next a').attr('href');
55 }
56 });
57
58 /* Select previous card. If there's a previous page, go to next page */
59 Mousetrap.bind('left', () => {
60 if (cardIndex > 0 && cardIndex < cardNumber) {
61 toggleFocus(card);
62 cardIndex -= 1;
63 card = cards[cardIndex];
64 toggleFocus(card);
65 return;
66 }
67 if (pagination.length > 0 && $(pagination).find('li.prev:not(.disabled)').length > 0 && cardIndex === 0) {
68 window.location.href = `${window.location.origin + $(pagination).find('li.prev a').attr('href')}#prev`;
69 }
70 });
71
72 Mousetrap.bind('enter', () => {
73 window.location.href = window.location.origin + $(card).find('span.card-title a').attr('href');
74 });
75});