]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/_global/index.js
Highlight code in articles using highlight.js
[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 /* Hightlight */
17 import './js/highlight';
18
19 import { savePercent, retrievePercent } from './js/tools';
20
21 /* ==========================================================================
22 Annotations & Remember position
23 ========================================================================== */
24
25 $(document).ready(() => {
26 if ($('article').length) {
27 const app = new annotator.App();
28
29 app.include(annotator.ui.main, {
30 element: document.querySelector('article'),
31 });
32
33 const authorization = {
34 permits() { return true; },
35 };
36 app.registry.registerUtility(authorization, 'authorizationPolicy');
37
38 const x = JSON.parse($('#annotationroutes').html());
39 app.include(annotator.storage.http, $.extend({}, x, {
40 onError(msg, xhr) {
41 if (!Object.prototype.hasOwnProperty.call(xhr, 'responseJSON')) {
42 annotator.notification.banner('An error occurred', 'error');
43 return;
44 }
45 $.each(xhr.responseJSON.children, (k, v) => {
46 if (v.errors) {
47 $.each(v.errors, (n, errorText) => {
48 annotator.notification.banner(errorText, 'error');
49 });
50 }
51 });
52 },
53 }));
54
55 app.start().then(() => {
56 app.annotations.load({ entry: x.entryId });
57 });
58
59 $(window).scroll(() => {
60 const scrollTop = $(window).scrollTop();
61 const docHeight = $(document).height();
62 const scrollPercent = (scrollTop) / (docHeight);
63 const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
64 savePercent(x.entryId, scrollPercentRounded);
65 });
66
67 retrievePercent(x.entryId);
68
69 $(window).resize(() => {
70 retrievePercent(x.entryId);
71 });
72 }
73 });