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