]>
Commit | Line | Data |
---|---|---|
64f81bc3 TC |
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 | ||
e317a5ab | 12 | /* Shortcuts */ |
64f81bc3 TC |
13 | import './js/shortcuts/entry'; |
14 | import './js/shortcuts/main'; | |
15 | ||
b2e7b8b6 FL |
16 | /* Hightlight */ |
17 | import './js/highlight'; | |
64f81bc3 | 18 | |
b2e7b8b6 | 19 | import { savePercent, retrievePercent } from './js/tools'; |
64f81bc3 TC |
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 | ||
60c52289 | 33 | const authorization = { |
34 | permits() { return true; }, | |
35 | }; | |
36 | app.registry.registerUtility(authorization, 'authorizationPolicy'); | |
37 | ||
64f81bc3 | 38 | const x = JSON.parse($('#annotationroutes').html()); |
2c3e148b | 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 | })); | |
64f81bc3 TC |
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(() => { | |
f136d288 | 70 | retrievePercent(x.entryId, true); |
64f81bc3 TC |
71 | }); |
72 | } | |
9b0aef91 SH |
73 | |
74 | document.querySelectorAll('[data-handler=tag-rename]').forEach((item) => { | |
75 | const current = item; | |
76 | current.wallabag_edit_mode = false; | |
77 | current.onclick = (event) => { | |
78 | const target = event.currentTarget; | |
79 | ||
80 | if (target.wallabag_edit_mode === false) { | |
81 | $(target.parentNode.querySelector('[data-handle=tag-link]')).addClass('hidden'); | |
82 | $(target.parentNode.querySelector('[data-handle=tag-rename-form]')).removeClass('hidden'); | |
83 | target.parentNode.querySelector('[data-handle=tag-rename-form] input').focus(); | |
84 | target.querySelector('.material-icons').innerHTML = 'done'; | |
85 | ||
86 | target.wallabag_edit_mode = true; | |
87 | } else { | |
88 | target.parentNode.querySelector('[data-handle=tag-rename-form]').submit(); | |
89 | } | |
90 | }; | |
91 | }); | |
64f81bc3 | 92 | }); |