aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes/_global/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/Resources/static/themes/_global/index.js')
-rw-r--r--app/Resources/static/themes/_global/index.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/Resources/static/themes/_global/index.js b/app/Resources/static/themes/_global/index.js
new file mode 100644
index 00000000..3fdcaa3d
--- /dev/null
+++ b/app/Resources/static/themes/_global/index.js
@@ -0,0 +1,57 @@
1/* jQuery */
2import $ from 'jquery';
3
4/* Annotations */
5import annotator from 'annotator';
6
7/* Fonts */
8import 'material-design-icons-iconfont/dist/material-design-icons.css';
9import 'lato-font/css/lato-font.css';
10import './global.scss';
11
12/* Shortcuts*/
13import './js/shortcuts/entry';
14import './js/shortcuts/main';
15
16import { savePercent, retrievePercent } from './js/tools';
17
18
19/* ==========================================================================
20 Annotations & Remember position
21 ========================================================================== */
22
23$(document).ready(() => {
24 if ($('article').length) {
25 const app = new annotator.App();
26
27 app.include(annotator.ui.main, {
28 element: document.querySelector('article'),
29 });
30
31 const authorization = {
32 permits() { return true; },
33 };
34 app.registry.registerUtility(authorization, 'authorizationPolicy');
35
36 const x = JSON.parse($('#annotationroutes').html());
37 app.include(annotator.storage.http, x);
38
39 app.start().then(() => {
40 app.annotations.load({ entry: x.entryId });
41 });
42
43 $(window).scroll(() => {
44 const scrollTop = $(window).scrollTop();
45 const docHeight = $(document).height();
46 const scrollPercent = (scrollTop) / (docHeight);
47 const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
48 savePercent(x.entryId, scrollPercentRounded);
49 });
50
51 retrievePercent(x.entryId);
52
53 $(window).resize(() => {
54 retrievePercent(x.entryId);
55 });
56 }
57});