aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes/_global/js/tools.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/Resources/static/themes/_global/js/tools.js')
-rw-r--r--app/Resources/static/themes/_global/js/tools.js66
1 files changed, 47 insertions, 19 deletions
diff --git a/app/Resources/static/themes/_global/js/tools.js b/app/Resources/static/themes/_global/js/tools.js
index 774f4539..6386688b 100644
--- a/app/Resources/static/themes/_global/js/tools.js
+++ b/app/Resources/static/themes/_global/js/tools.js
@@ -5,30 +5,58 @@ import './shortcuts/entry';
5/* Allows inline call qr-code call */ 5/* Allows inline call qr-code call */
6import jrQrcode from 'jr-qrcode'; // eslint-disable-line 6import jrQrcode from 'jr-qrcode'; // eslint-disable-line
7 7
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) { 8function savePercent(id, percent) {
17 if (!supportsLocalStorage()) { return false; } 9 fetch(`/progress/${id}/${percent * 100}`, { credentials: 'include' });
18 localStorage[`wallabag.article.${id}.percent`] = percent;
19 return true;
20} 10}
21 11
22function retrievePercent(id) { 12function retrievePercent() {
23 if (!supportsLocalStorage()) { return false; } 13 const percent = $('#article').attr('data-progress');
24 14 console.log(percent);
25 const bheight = $(document).height(); 15 const scroll = $(document).height() * percent;
26 const percent = localStorage[`wallabag.article.${id}.percent`];
27 const scroll = bheight * percent;
28 16
29 $('html,body').animate({ scrollTop: scroll }, 'fast'); 17 $('html,body').animate({ scrollTop: scroll }, 'fast');
18}
19
20function 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
33function 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}
30 40
31 return true; 41function 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 };
32} 60}
33 61
34export { savePercent, retrievePercent }; 62export { savePercent, retrievePercent, initFilters, initExport, throttle };