]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/_global/js/tools.js
es6 imports
[github/wallabag/wallabag.git] / app / Resources / static / themes / _global / js / tools.js
CommitLineData
af61cb80
TC
1import $ from 'jquery';
2import Mousetrap from 'mousetrap';
c146f694 3
32508ef0
TC
4/* Allows inline call qr-code call */
5import jrQrcode from 'jr-qrcode'; // eslint-disable-line
e61ee560 6
c146f694
TC
7function supportsLocalStorage() {
8 try {
9 return 'localStorage' in window && window.localStorage !== null;
10 } catch (e) {
11 return false;
12 }
13}
14
15function savePercent(id, percent) {
16 if (!supportsLocalStorage()) { return false; }
17 localStorage[`wallabag.article.${id}.percent`] = percent;
18 return true;
19}
20
21function retrievePercent(id) {
22 if (!supportsLocalStorage()) { return false; }
23
24 const bheight = $(document).height();
25 const percent = localStorage[`wallabag.article.${id}.percent`];
26 const scroll = bheight * percent;
27
28 $('html,body').animate({ scrollTop: scroll }, 'fast');
29
30 return true;
31}
32
33function initFilters() {
34 // no display if filters not available
35 if ($('div').is('#filters')) {
36 $('#button_filters').show();
37 $('.button-collapse-right').sideNav({ edge: 'right' });
38 $('#clear_form_filters').on('click', () => {
39 $('#filters input').val('');
40 $('#filters :checked').removeAttr('checked');
41 return false;
42 });
43 }
44}
45
46function initExport() {
47 // no display if export not available
48 if ($('div').is('#export')) {
49 $('#button_export').show();
50 $('.button-collapse-right').sideNav({ edge: 'right' });
51 }
52}
53
54export { savePercent, retrievePercent, initFilters, initExport };
3cc78f06
NL
55
56/** Shortcuts **/
57
58/* Go to */
af61cb80
TC
59Mousetrap.bind('g u', () => { window.location.href = Routing.generate('homepage'); });
60Mousetrap.bind('g s', () => { window.location.href = Routing.generate('starred'); });
61Mousetrap.bind('g r', () => { window.location.href = Routing.generate('archive'); });
62Mousetrap.bind('g a', () => { window.location.href = Routing.generate('all'); });
63Mousetrap.bind('g t', () => { window.location.href = Routing.generate('tag'); });
64Mousetrap.bind('g c', () => { window.location.href = Routing.generate('config'); });
65Mousetrap.bind('g i', () => { window.location.href = Routing.generate('import'); });
66Mousetrap.bind('g d', () => { window.location.href = Routing.generate('developer'); });
67Mousetrap.bind('g h', () => { window.location.href = Routing.generate('howto'); });
68Mousetrap.bind('g l', () => { window.location.href = Routing.generate('logout'); });
f9cded7d 69
3cc78f06
NL
70
71/* Actions */
af61cb80
TC
72Mousetrap.bind('g n', () => {
73 $('#nav-btn-add').trigger('click');
3cc78f06 74});
f9cded7d 75
af61cb80
TC
76Mousetrap.bind('esc', () => {
77 $('.close').trigger('click');
f9cded7d
NL
78});
79
80// Display the first element of the current view
af61cb80
TC
81Mousetrap.bind('right', () => {
82 $('ul.data li:first-child span.dot-ellipsis a')[0].click();
f9cded7d
NL
83});
84
85/* Article view */
af61cb80
TC
86Mousetrap.bind('o', () => {
87 $('ul.side-nav li:nth-child(2) a i')[0].click();
f9cded7d
NL
88});
89
af61cb80
TC
90Mousetrap.bind('s', () => {
91 $('ul.side-nav li:nth-child(5) a i')[0].click();
f9cded7d
NL
92});
93
af61cb80
TC
94Mousetrap.bind('a', () => {
95 $('ul.side-nav li:nth-child(4) a i')[0].click();
f9cded7d
NL
96});
97
af61cb80
TC
98Mousetrap.bind('del', () => {
99 $('ul.side-nav li:nth-child(6) a i')[0].click();
f9cded7d 100});