]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/_global/js/tools.js
Reorganized JS folders for shortcuts
[github/wallabag/wallabag.git] / app / Resources / static / themes / _global / js / tools.js
1 import $ from 'jquery';
2 import Mousetrap from 'mousetrap';
3 import './shortcuts/main.js';
4 import './shortcuts/entry.js';
5
6 /* Allows inline call qr-code call */
7 import jrQrcode from 'jr-qrcode'; // eslint-disable-line
8
9 function supportsLocalStorage() {
10 try {
11 return 'localStorage' in window && window.localStorage !== null;
12 } catch (e) {
13 return false;
14 }
15 }
16
17 function savePercent(id, percent) {
18 if (!supportsLocalStorage()) { return false; }
19 localStorage[`wallabag.article.${id}.percent`] = percent;
20 return true;
21 }
22
23 function retrievePercent(id) {
24 if (!supportsLocalStorage()) { return false; }
25
26 const bheight = $(document).height();
27 const percent = localStorage[`wallabag.article.${id}.percent`];
28 const scroll = bheight * percent;
29
30 $('html,body').animate({ scrollTop: scroll }, 'fast');
31
32 return true;
33 }
34
35 function initFilters() {
36 // no display if filters not available
37 if ($('div').is('#filters')) {
38 $('#button_filters').show();
39 $('.button-collapse-right').sideNav({ edge: 'right' });
40 $('#clear_form_filters').on('click', () => {
41 $('#filters input').val('');
42 $('#filters :checked').removeAttr('checked');
43 return false;
44 });
45 }
46 }
47
48 function initExport() {
49 // no display if export not available
50 if ($('div').is('#export')) {
51 $('#button_export').show();
52 $('.button-collapse-right').sideNav({ edge: 'right' });
53 }
54 }
55
56 export { savePercent, retrievePercent, initFilters, initExport };