mirror of
https://github.com/wallabag/wallabag.git
synced 2024-09-28 14:22:02 +00:00
9b0aef9171
* Add a form on each tag to handle rename action. * Add JavaScript to handle action on the corresponding page inside the global index.js file. * Add support for the 2 active themes : material / baggy The form solution is cleaner than an Ajax one because it let the browser validate input data and make the POST easier without the need to handle JSON response.
92 lines
2.7 KiB
JavaScript
92 lines
2.7 KiB
JavaScript
/* jQuery */
|
|
import $ from 'jquery';
|
|
|
|
/* Annotations */
|
|
import annotator from 'annotator';
|
|
|
|
/* Fonts */
|
|
import 'material-design-icons-iconfont/dist/material-design-icons.css';
|
|
import 'lato-font/css/lato-font.css';
|
|
import './global.scss';
|
|
|
|
/* Shortcuts */
|
|
import './js/shortcuts/entry';
|
|
import './js/shortcuts/main';
|
|
|
|
/* Hightlight */
|
|
import './js/highlight';
|
|
|
|
import { savePercent, retrievePercent } from './js/tools';
|
|
|
|
/* ==========================================================================
|
|
Annotations & Remember position
|
|
========================================================================== */
|
|
|
|
$(document).ready(() => {
|
|
if ($('article').length) {
|
|
const app = new annotator.App();
|
|
|
|
app.include(annotator.ui.main, {
|
|
element: document.querySelector('article'),
|
|
});
|
|
|
|
const authorization = {
|
|
permits() { return true; },
|
|
};
|
|
app.registry.registerUtility(authorization, 'authorizationPolicy');
|
|
|
|
const x = JSON.parse($('#annotationroutes').html());
|
|
app.include(annotator.storage.http, $.extend({}, x, {
|
|
onError(msg, xhr) {
|
|
if (!Object.prototype.hasOwnProperty.call(xhr, 'responseJSON')) {
|
|
annotator.notification.banner('An error occurred', 'error');
|
|
return;
|
|
}
|
|
$.each(xhr.responseJSON.children, (k, v) => {
|
|
if (v.errors) {
|
|
$.each(v.errors, (n, errorText) => {
|
|
annotator.notification.banner(errorText, 'error');
|
|
});
|
|
}
|
|
});
|
|
},
|
|
}));
|
|
|
|
app.start().then(() => {
|
|
app.annotations.load({ entry: x.entryId });
|
|
});
|
|
|
|
$(window).scroll(() => {
|
|
const scrollTop = $(window).scrollTop();
|
|
const docHeight = $(document).height();
|
|
const scrollPercent = (scrollTop) / (docHeight);
|
|
const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
|
|
savePercent(x.entryId, scrollPercentRounded);
|
|
});
|
|
|
|
retrievePercent(x.entryId);
|
|
|
|
$(window).resize(() => {
|
|
retrievePercent(x.entryId, true);
|
|
});
|
|
}
|
|
|
|
document.querySelectorAll('[data-handler=tag-rename]').forEach((item) => {
|
|
const current = item;
|
|
current.wallabag_edit_mode = false;
|
|
current.onclick = (event) => {
|
|
const target = event.currentTarget;
|
|
|
|
if (target.wallabag_edit_mode === false) {
|
|
$(target.parentNode.querySelector('[data-handle=tag-link]')).addClass('hidden');
|
|
$(target.parentNode.querySelector('[data-handle=tag-rename-form]')).removeClass('hidden');
|
|
target.parentNode.querySelector('[data-handle=tag-rename-form] input').focus();
|
|
target.querySelector('.material-icons').innerHTML = 'done';
|
|
|
|
target.wallabag_edit_mode = true;
|
|
} else {
|
|
target.parentNode.querySelector('[data-handle=tag-rename-form]').submit();
|
|
}
|
|
};
|
|
});
|
|
});
|