]>
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';
10 import 'material-design-icons-iconfont/dist/material-design-icons.css';
11 import 'lato-font/css/lato-font.css';
12 import './global.scss';
15 import './js/shortcuts/entry';
16 import './js/shortcuts/main';
19 import './js/highlight';
21 import { savePercent
, retrievePercent
} from './js/tools';
23 /* ==========================================================================
24 Annotations & Remember position
25 ========================================================================== */
27 $(document
).ready(() => {
28 if ($('article').length
) {
29 const app
= new annotator
.App();
31 app
.include(annotator
.ui
.main
, {
32 element: document
.querySelector('article'),
35 const authorization
= {
36 permits() { return true; },
38 app
.registry
.registerUtility(authorization
, 'authorizationPolicy');
40 const x
= JSON
.parse($('#annotationroutes').html());
41 app
.include(annotator
.storage
.http
, $.extend({}, x
, {
43 if (!Object
.prototype.hasOwnProperty
.call(xhr
, 'responseJSON')) {
44 annotator
.notification
.banner('An error occurred', 'error');
47 $.each(xhr
.responseJSON
.children
, (k
, v
) => {
49 $.each(v
.errors
, (n
, errorText
) => {
50 annotator
.notification
.banner(errorText
, 'error');
57 app
.start().then(() => {
58 app
.annotations
.load({ entry: x
.entryId
});
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
);
69 retrievePercent(x
.entryId
);
71 $(window
).resize(() => {
72 retrievePercent(x
.entryId
, true);
76 document
.querySelectorAll('[data-handler=tag-rename]').forEach((item
) => {
78 current
.wallabag_edit_mode
= false;
79 current
.onclick
= (event
) => {
80 const target
= event
.currentTarget
;
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';
88 target
.wallabag_edit_mode
= true;
90 target
.parentNode
.querySelector('[data-handle=tag-rename-form]').submit();
95 // mimic radio button because emailTwoFactor is a boolean
96 $('#update_user_googleTwoFactor').on('change', () => {
97 $('#update_user_emailTwoFactor').prop('checked', false);
100 $('#update_user_emailTwoFactor').on('change', () => {
101 $('#update_user_googleTwoFactor').prop('checked', false);
104 // same mimic for super admin
105 $('#user_googleTwoFactor').on('change', () => {
106 $('#user_emailTwoFactor').prop('checked', false);
109 $('#user_emailTwoFactor').on('change', () => {
110 $('#user_googleTwoFactor').prop('checked', false);
113 // handle copy to clipboard for developer stuff
114 const clipboard
= new ClipboardJS('.btn');
115 clipboard
.on('success', (e
) => {