diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Resources/static/themes/_global/js/tools.js | 66 | ||||
-rwxr-xr-x | app/Resources/static/themes/baggy/index.js | 36 | ||||
-rwxr-xr-x | app/Resources/static/themes/material/index.js | 33 |
3 files changed, 116 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 */ |
6 | import jrQrcode from 'jr-qrcode'; // eslint-disable-line | 6 | import jrQrcode from 'jr-qrcode'; // eslint-disable-line |
7 | 7 | ||
8 | function supportsLocalStorage() { | ||
9 | try { | ||
10 | return 'localStorage' in window && window.localStorage !== null; | ||
11 | } catch (e) { | ||
12 | return false; | ||
13 | } | ||
14 | } | ||
15 | |||
16 | function savePercent(id, percent) { | 8 | function 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 | ||
22 | function retrievePercent(id) { | 12 | function 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 | |||
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 | } | ||
30 | 40 | ||
31 | return true; | 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 | }; | ||
32 | } | 60 | } |
33 | 61 | ||
34 | export { savePercent, retrievePercent }; | 62 | export { savePercent, retrievePercent, initFilters, initExport, throttle }; |
diff --git a/app/Resources/static/themes/baggy/index.js b/app/Resources/static/themes/baggy/index.js index 39ad49aa..27e3e374 100755 --- a/app/Resources/static/themes/baggy/index.js +++ b/app/Resources/static/themes/baggy/index.js | |||
@@ -9,6 +9,9 @@ import './js/shortcuts/entry'; | |||
9 | 9 | ||
10 | /* Tools */ | 10 | /* Tools */ |
11 | import toggleSaveLinkForm from './js/uiTools'; | 11 | import toggleSaveLinkForm from './js/uiTools'; |
12 | import {savePercent, retrievePercent, throttle} from '../_global/js/tools'; | ||
13 | |||
14 | global.jquery = $; | ||
12 | 15 | ||
13 | /* Theme style */ | 16 | /* Theme style */ |
14 | import './css/index.scss'; | 17 | import './css/index.scss'; |
@@ -50,6 +53,39 @@ $(document).ready(() => { | |||
50 | }); | 53 | }); |
51 | } | 54 | } |
52 | 55 | ||
56 | /* ========================================================================== | ||
57 | Annotations & Remember position | ||
58 | ========================================================================== */ | ||
59 | |||
60 | if ($('article').length) { | ||
61 | const app = new annotator.App(); | ||
62 | |||
63 | app.include(annotator.ui.main, { | ||
64 | element: document.querySelector('article'), | ||
65 | }); | ||
66 | |||
67 | const x = JSON.parse($('#annotationroutes').html()); | ||
68 | app.include(annotator.storage.http, x); | ||
69 | |||
70 | app.start().then(() => { | ||
71 | app.annotations.load({ entry: x.entryId }); | ||
72 | }); | ||
73 | |||
74 | window.addEventListener('unload', () => { | ||
75 | const scrollTop = $(window).scrollTop(); | ||
76 | const docHeight = $(document).height(); | ||
77 | const scrollPercent = (scrollTop) / (docHeight); | ||
78 | const scrollPercentRounded = Math.round(scrollPercent * 100) / 100; | ||
79 | savePercent(x.entryId, scrollPercentRounded); | ||
80 | }); | ||
81 | |||
82 | retrievePercent(x.entryId); | ||
83 | |||
84 | $(window).resize(() => { | ||
85 | retrievePercent(x.entryId); | ||
86 | }); | ||
87 | } | ||
88 | |||
53 | /** | 89 | /** |
54 | * Close window after adding entry if popup | 90 | * Close window after adding entry if popup |
55 | */ | 91 | */ |
diff --git a/app/Resources/static/themes/material/index.js b/app/Resources/static/themes/material/index.js index d6afbb8a..408528ea 100755 --- a/app/Resources/static/themes/material/index.js +++ b/app/Resources/static/themes/material/index.js | |||
@@ -75,4 +75,37 @@ $(document).ready(() => { | |||
75 | const scrollPercent = (s / (d - c)) * 100; | 75 | const scrollPercent = (s / (d - c)) * 100; |
76 | $('.progress .determinate').css('width', `${scrollPercent}%`); | 76 | $('.progress .determinate').css('width', `${scrollPercent}%`); |
77 | }); | 77 | }); |
78 | |||
79 | /* ========================================================================== | ||
80 | Annotations & Remember position | ||
81 | ========================================================================== */ | ||
82 | |||
83 | if ($('article').length) { | ||
84 | const app = new annotator.App(); | ||
85 | const x = JSON.parse($('#annotationroutes').html()); | ||
86 | |||
87 | app.include(annotator.ui.main, { | ||
88 | element: document.querySelector('article'), | ||
89 | }); | ||
90 | |||
91 | app.include(annotator.storage.http, x); | ||
92 | |||
93 | app.start().then(() => { | ||
94 | app.annotations.load({ entry: x.entryId }); | ||
95 | }); | ||
96 | |||
97 | window.addEventListener('unload', () => { | ||
98 | const scrollTop = $(window).scrollTop(); | ||
99 | const docHeight = $(document).height(); | ||
100 | const scrollPercent = (scrollTop) / (docHeight); | ||
101 | const scrollPercentRounded = Math.round(scrollPercent * 100) / 100; | ||
102 | savePercent(x.entryId, scrollPercentRounded); | ||
103 | }); | ||
104 | |||
105 | retrievePercent(x.entryId); | ||
106 | |||
107 | $(window).resize(() => { | ||
108 | retrievePercent(x.entryId); | ||
109 | }); | ||
110 | } | ||
78 | }); | 111 | }); |