]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/_global/index.js
2 import $ from 'jquery';
5 import annotator
from 'annotator';
7 import ClipboardJS
from 'clipboard';
8 import 'mathjax/es5/tex-svg';
11 import 'material-design-icons-iconfont/dist/material-design-icons.css';
12 import 'lato-font/css/lato-font.css';
13 import './global.scss';
16 import './js/shortcuts/entry';
17 import './js/shortcuts/main';
20 import './js/highlight';
22 import { savePercent
, retrievePercent
} from './js/tools';
24 /* ==========================================================================
25 Annotations & Remember position
26 ========================================================================== */
28 $(document
).ready(() => {
29 if ($('article').length
) {
30 const app
= new annotator
.App();
32 app
.include(annotator
.ui
.main
, {
33 element: document
.querySelector('article'),
36 const authorization
= {
37 permits() { return true; },
39 app
.registry
.registerUtility(authorization
, 'authorizationPolicy');
41 const x
= JSON
.parse($('#annotationroutes').html());
42 app
.include(annotator
.storage
.http
, $.extend({}, x
, {
44 if (!Object
.prototype.hasOwnProperty
.call(xhr
, 'responseJSON')) {
45 annotator
.notification
.banner('An error occurred', 'error');
48 $.each(xhr
.responseJSON
.children
, (k
, v
) => {
50 $.each(v
.errors
, (n
, errorText
) => {
51 annotator
.notification
.banner(errorText
, 'error');
58 app
.start().then(() => {
59 app
.annotations
.load({ entry: x
.entryId
});
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
);
70 retrievePercent(x
.entryId
);
72 $(window
).resize(() => {
73 retrievePercent(x
.entryId
, true);
77 document
.querySelectorAll('[data-handler=tag-rename]').forEach((item
) => {
79 current
.wallabag_edit_mode
= false;
80 current
.onclick
= (event
) => {
81 const target
= event
.currentTarget
;
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';
89 target
.wallabag_edit_mode
= true;
91 target
.parentNode
.querySelector('[data-handle=tag-rename-form]').submit();
96 // mimic radio button because emailTwoFactor is a boolean
97 $('#update_user_googleTwoFactor').on('change', () => {
98 $('#update_user_emailTwoFactor').prop('checked', false);
101 $('#update_user_emailTwoFactor').on('change', () => {
102 $('#update_user_googleTwoFactor').prop('checked', false);
105 // same mimic for super admin
106 $('#user_googleTwoFactor').on('change', () => {
107 $('#user_emailTwoFactor').prop('checked', false);
110 $('#user_emailTwoFactor').on('change', () => {
111 $('#user_googleTwoFactor').prop('checked', false);
114 // handle copy to clipboard for developer stuff
115 const clipboard
= new ClipboardJS('.btn');
116 clipboard
.on('success', (e
) => {