aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes
diff options
context:
space:
mode:
Diffstat (limited to 'app/Resources/static/themes')
-rw-r--r--app/Resources/static/themes/_global/js/tools.js66
-rwxr-xr-xapp/Resources/static/themes/baggy/index.js36
-rwxr-xr-xapp/Resources/static/themes/material/index.js33
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 */
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 };
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 */
11import toggleSaveLinkForm from './js/uiTools'; 11import toggleSaveLinkForm from './js/uiTools';
12import {savePercent, retrievePercent, throttle} from '../_global/js/tools';
13
14global.jquery = $;
12 15
13/* Theme style */ 16/* Theme style */
14import './css/index.scss'; 17import './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});