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