]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/_global/index.js
Added MathJax support
[github/wallabag/wallabag.git] / app / Resources / static / themes / _global / index.js
CommitLineData
64f81bc3
TC
1/* jQuery */
2import $ from 'jquery';
3
4/* Annotations */
5import annotator from 'annotator';
6
66fa0c26 7import ClipboardJS from 'clipboard';
2f5fa30a 8import 'mathjax/es5/tex-svg';
66fa0c26 9
64f81bc3
TC
10/* Fonts */
11import 'material-design-icons-iconfont/dist/material-design-icons.css';
12import 'lato-font/css/lato-font.css';
13import './global.scss';
14
e317a5ab 15/* Shortcuts */
64f81bc3
TC
16import './js/shortcuts/entry';
17import './js/shortcuts/main';
18
b2e7b8b6
FL
19/* Hightlight */
20import './js/highlight';
64f81bc3 21
b2e7b8b6 22import { savePercent, retrievePercent } from './js/tools';
64f81bc3
TC
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
60c52289 36 const authorization = {
37 permits() { return true; },
38 };
39 app.registry.registerUtility(authorization, 'authorizationPolicy');
40
64f81bc3 41 const x = JSON.parse($('#annotationroutes').html());
2c3e148b 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 }));
64f81bc3
TC
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(() => {
f136d288 73 retrievePercent(x.entryId, true);
64f81bc3
TC
74 });
75 }
9b0aef91
SH
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 });
a6b242a1
JB
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 });
66fa0c26
JB
113
114 // handle copy to clipboard for developer stuff
115 const clipboard = new ClipboardJS('.btn');
116 clipboard.on('success', (e) => {
66fa0c26
JB
117 e.clearSelection();
118 });
64f81bc3 119});