]>
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';
8 import 'material-design-icons-iconfont/dist/material-design-icons.css';
9 import 'lato-font/css/lato-font.css';
10 import './global.scss';
13 import './js/shortcuts/entry';
14 import './js/shortcuts/main';
17 import './js/highlight';
19 import { savePercent
, retrievePercent
} from './js/tools';
21 /* ==========================================================================
22 Annotations & Remember position
23 ========================================================================== */
25 $(document
).ready(() => {
26 if ($('article').length
) {
27 const app
= new annotator
.App();
29 app
.include(annotator
.ui
.main
, {
30 element: document
.querySelector('article'),
33 const authorization
= {
34 permits() { return true; },
36 app
.registry
.registerUtility(authorization
, 'authorizationPolicy');
38 const x
= JSON
.parse($('#annotationroutes').html());
39 app
.include(annotator
.storage
.http
, $.extend({}, x
, {
41 if (!Object
.prototype.hasOwnProperty
.call(xhr
, 'responseJSON')) {
42 annotator
.notification
.banner('An error occurred', 'error');
45 $.each(xhr
.responseJSON
.children
, (k
, v
) => {
47 $.each(v
.errors
, (n
, errorText
) => {
48 annotator
.notification
.banner(errorText
, 'error');
55 app
.start().then(() => {
56 app
.annotations
.load({ entry: x
.entryId
});
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
);
67 retrievePercent(x
.entryId
);
69 $(window
).resize(() => {
70 retrievePercent(x
.entryId
, true);
74 document
.querySelectorAll('[data-handler=tag-rename]').forEach((item
) => {
76 current
.wallabag_edit_mode
= false;
77 current
.onclick
= (event
) => {
78 const target
= event
.currentTarget
;
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';
86 target
.wallabag_edit_mode
= true;
88 target
.parentNode
.querySelector('[data-handle=tag-rename-form]').submit();