diff options
Diffstat (limited to 'app/Resources/static/themes/material')
3 files changed, 106 insertions, 3 deletions
diff --git a/app/Resources/static/themes/material/js/init.js b/app/Resources/static/themes/material/js/init.js index a68269e0..9746224b 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 */ | ||
2 | import $ from 'jquery'; | ||
3 | |||
4 | /* Annotations */ | ||
5 | import annotator from 'annotator'; | ||
6 | |||
7 | /* Tools */ | ||
1 | import { savePercent, retrievePercent, initFilters, initExport } from '../../_global/js/tools'; | 8 | import { savePercent, retrievePercent, initFilters, initExport } from '../../_global/js/tools'; |
2 | 9 | ||
3 | const $ = require('jquery'); | 10 | /* Import shortcuts */ |
11 | import './shortcuts/main'; | ||
12 | import './shortcuts/entry'; | ||
13 | import '../../_global/js/shortcuts/main'; | ||
14 | import '../../_global/js/shortcuts/entry'; | ||
4 | 15 | ||
5 | global.jQuery = $; | ||
6 | require('materialize'); // eslint-disable-line | 16 | require('materialize'); // eslint-disable-line |
7 | const annotator = require('annotator'); | 17 | |
18 | global.jQuery = $; | ||
8 | 19 | ||
9 | $(document).ready(() => { | 20 | $(document).ready(() => { |
10 | // sideNav | 21 | // sideNav |
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..357c22fe --- /dev/null +++ b/app/Resources/static/themes/material/js/shortcuts/entry.js | |||
@@ -0,0 +1,22 @@ | |||
1 | import Mousetrap from 'mousetrap'; | ||
2 | import $ from 'jquery'; | ||
3 | |||
4 | /* open original article */ | ||
5 | Mousetrap.bind('o', () => { | ||
6 | $('ul.side-nav a.original i')[0].click(); | ||
7 | }); | ||
8 | |||
9 | /* mark as favorite */ | ||
10 | Mousetrap.bind('s', () => { | ||
11 | $('ul.side-nav a.favorite i')[0].click(); | ||
12 | }); | ||
13 | |||
14 | /* mark as read */ | ||
15 | Mousetrap.bind('a', () => { | ||
16 | $('ul.side-nav a.markasread i')[0].click(); | ||
17 | }); | ||
18 | |||
19 | /* delete */ | ||
20 | Mousetrap.bind('del', () => { | ||
21 | $('ul.side-nav a.delete i')[0].click(); | ||
22 | }); | ||
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..8514f71e --- /dev/null +++ b/app/Resources/static/themes/material/js/shortcuts/main.js | |||
@@ -0,0 +1,70 @@ | |||
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 | }); | ||
34 | |||
35 | Mousetrap.bind('esc', () => { | ||
36 | $('.close').trigger('click'); | ||
37 | }); | ||
38 | |||
39 | /* Select right card. If there's a next page, go to next page */ | ||
40 | Mousetrap.bind('right', () => { | ||
41 | if (cardIndex >= 0 && cardIndex < cardNumber - 1) { | ||
42 | toggleFocus(card); | ||
43 | cardIndex += 1; | ||
44 | card = $('ul.data > li')[cardIndex]; | ||
45 | toggleFocus(card); | ||
46 | return; | ||
47 | } | ||
48 | if (pagination.length > 0 && pagination.find('li.next:not(.disabled)').length > 0 && cardIndex === cardNumber - 1) { | ||
49 | window.location.href = window.location.origin + $(pagination).find('li.next a').attr('href'); | ||
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.length > 0 && $(pagination).find('li.prev:not(.disabled)').length > 0 && cardIndex === 0) { | ||
63 | window.location.href = `${window.location.origin + $(pagination).find('li.prev a').attr('href')}#prev`; | ||
64 | } | ||
65 | }); | ||
66 | |||
67 | Mousetrap.bind('enter', () => { | ||
68 | window.location.href = window.location.origin + $(card).find('span.card-title a').attr('href'); | ||
69 | }); | ||
70 | }); | ||