]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/_global/js/tools.js
Set progress
[github/wallabag/wallabag.git] / app / Resources / static / themes / _global / js / tools.js
1 import $ from 'jquery';
2 import './shortcuts/main';
3 import './shortcuts/entry';
4
5 /* Allows inline call qr-code call */
6 import jrQrcode from 'jr-qrcode'; // eslint-disable-line
7
8 function savePercent(id, percent) {
9 fetch(`/progress/${id}/${percent * 100}`, { credentials: 'include' });
10 }
11
12 function retrievePercent() {
13 const percent = $('#article').attr('data-progress');
14 console.log(percent);
15 const scroll = $(document).height() * percent;
16
17 $('html,body').animate({ scrollTop: scroll }, 'fast');
18 }
19
20 function initFilters() {
21 // no display if filters not available
22 if ($('div').is('#filters')) {
23 $('#button_filters').show();
24 $('.js-filters-action').sideNav({ edge: 'right' });
25 $('#clear_form_filters').on('click', () => {
26 $('#filters input').val('');
27 $('#filters :checked').removeAttr('checked');
28 return false;
29 });
30 }
31 }
32
33 function initExport() {
34 // no display if export not available
35 if ($('div').is('#export')) {
36 $('#button_export').show();
37 $('.js-export-action').sideNav({ edge: 'right' });
38 }
39 }
40
41 function throttle(callback, delay) {
42 let last;
43 let timer;
44 return function () {
45 const context = this;
46 const now = new Date();
47 const args = arguments;
48 if (last && now < last + delay) {
49 // le délai n'est pas écoulé on reset le timer
50 clearTimeout(timer);
51 timer = setTimeout(function () {
52 last = now;
53 callback.apply(context, args);
54 }, delay);
55 } else {
56 last = now;
57 callback.apply(context, args);
58 }
59 };
60 }
61
62 export { savePercent, retrievePercent, initFilters, initExport, throttle };