]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/_global/index.js
Added MathJax support
[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 import ClipboardJS from 'clipboard';
8 import 'mathjax/es5/tex-svg';
9
10 /* Fonts */
11 import 'material-design-icons-iconfont/dist/material-design-icons.css';
12 import 'lato-font/css/lato-font.css';
13 import './global.scss';
14
15 /* Shortcuts */
16 import './js/shortcuts/entry';
17 import './js/shortcuts/main';
18
19 /* Hightlight */
20 import './js/highlight';
21
22 import { savePercent, retrievePercent } from './js/tools';
23
24 /* ==========================================================================
25 Annotations & Remember position
26 ========================================================================== */
27
28 $(document).ready(() => {
29 if ($('article').length) {
30 const app = new annotator.App();
31
32 app.include(annotator.ui.main, {
33 element: document.querySelector('article'),
34 });
35
36 const authorization = {
37 permits() { return true; },
38 };
39 app.registry.registerUtility(authorization, 'authorizationPolicy');
40
41 const x = JSON.parse($('#annotationroutes').html());
42 app.include(annotator.storage.http, $.extend({}, x, {
43 onError(msg, xhr) {
44 if (!Object.prototype.hasOwnProperty.call(xhr, 'responseJSON')) {
45 annotator.notification.banner('An error occurred', 'error');
46 return;
47 }
48 $.each(xhr.responseJSON.children, (k, v) => {
49 if (v.errors) {
50 $.each(v.errors, (n, errorText) => {
51 annotator.notification.banner(errorText, 'error');
52 });
53 }
54 });
55 },
56 }));
57
58 app.start().then(() => {
59 app.annotations.load({ entry: x.entryId });
60 });
61
62 $(window).scroll(() => {
63 const scrollTop = $(window).scrollTop();
64 const docHeight = $(document).height();
65 const scrollPercent = (scrollTop) / (docHeight);
66 const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
67 savePercent(x.entryId, scrollPercentRounded);
68 });
69
70 retrievePercent(x.entryId);
71
72 $(window).resize(() => {
73 retrievePercent(x.entryId, true);
74 });
75 }
76
77 document.querySelectorAll('[data-handler=tag-rename]').forEach((item) => {
78 const current = item;
79 current.wallabag_edit_mode = false;
80 current.onclick = (event) => {
81 const target = event.currentTarget;
82
83 if (target.wallabag_edit_mode === false) {
84 $(target.parentNode.querySelector('[data-handle=tag-link]')).addClass('hidden');
85 $(target.parentNode.querySelector('[data-handle=tag-rename-form]')).removeClass('hidden');
86 target.parentNode.querySelector('[data-handle=tag-rename-form] input').focus();
87 target.querySelector('.material-icons').innerHTML = 'done';
88
89 target.wallabag_edit_mode = true;
90 } else {
91 target.parentNode.querySelector('[data-handle=tag-rename-form]').submit();
92 }
93 };
94 });
95
96 // mimic radio button because emailTwoFactor is a boolean
97 $('#update_user_googleTwoFactor').on('change', () => {
98 $('#update_user_emailTwoFactor').prop('checked', false);
99 });
100
101 $('#update_user_emailTwoFactor').on('change', () => {
102 $('#update_user_googleTwoFactor').prop('checked', false);
103 });
104
105 // same mimic for super admin
106 $('#user_googleTwoFactor').on('change', () => {
107 $('#user_emailTwoFactor').prop('checked', false);
108 });
109
110 $('#user_emailTwoFactor').on('change', () => {
111 $('#user_googleTwoFactor').prop('checked', false);
112 });
113
114 // handle copy to clipboard for developer stuff
115 const clipboard = new ClipboardJS('.btn');
116 clipboard.on('success', (e) => {
117 e.clearSelection();
118 });
119 });