]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/_global/index.js
Fix Firefox mobile unneeded resize
[github/wallabag/wallabag.git] / app / Resources / static / themes / _global / index.js
1 /* jQuery */
2 import $ from 'jquery';
3
4 /* Annotations */
5 import annotator from 'annotator';
6
7 /* Fonts */
8 import 'material-design-icons-iconfont/dist/material-design-icons.css';
9 import 'lato-font/css/lato-font.css';
10 import './global.scss';
11
12 /* Shortcuts */
13 import './js/shortcuts/entry';
14 import './js/shortcuts/main';
15
16 import { 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, $.extend({}, x, {
38 onError(msg, xhr) {
39 if (!Object.prototype.hasOwnProperty.call(xhr, 'responseJSON')) {
40 annotator.notification.banner('An error occurred', 'error');
41 return;
42 }
43 $.each(xhr.responseJSON.children, (k, v) => {
44 if (v.errors) {
45 $.each(v.errors, (n, errorText) => {
46 annotator.notification.banner(errorText, 'error');
47 });
48 }
49 });
50 },
51 }));
52
53 app.start().then(() => {
54 app.annotations.load({ entry: x.entryId });
55 });
56
57 $(window).scroll(() => {
58 const scrollTop = $(window).scrollTop();
59 const docHeight = $(document).height();
60 const scrollPercent = (scrollTop) / (docHeight);
61 const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
62 savePercent(x.entryId, scrollPercentRounded);
63 });
64
65 retrievePercent(x.entryId);
66
67 $(window).resize(() => {
68 retrievePercent(x.entryId, true);
69 });
70 }
71 });