]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/_global/js/tools.js
Added shortcuts
[github/wallabag/wallabag.git] / app / Resources / static / themes / _global / js / tools.js
1 const $ = require('jquery');
2 require('mousetrap');
3
4 /* Allows inline call qr-code call */
5 import jrQrcode from 'jr-qrcode'; // eslint-disable-line
6
7 function supportsLocalStorage() {
8 try {
9 return 'localStorage' in window && window.localStorage !== null;
10 } catch (e) {
11 return false;
12 }
13 }
14
15 function savePercent(id, percent) {
16 if (!supportsLocalStorage()) { return false; }
17 localStorage[`wallabag.article.${id}.percent`] = percent;
18 return true;
19 }
20
21 function 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
33 function 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
46 function 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
54 export { savePercent, retrievePercent, initFilters, initExport };
55
56 /** Shortcuts **/
57
58 /* Go to */
59 Mousetrap.bind('g u', function() { window.location.href = Routing.generate('homepage') });
60 Mousetrap.bind('g s', function() { window.location.href = Routing.generate('starred') });
61
62 /* Actions */
63 Mousetrap.bind('g a', function() {
64 $("#nav-btn-add").trigger("click");
65 });