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