]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/material/js/init.js
Reorganized JS folders for shortcuts
[github/wallabag/wallabag.git] / app / Resources / static / themes / material / js / init.js
CommitLineData
af61cb80
TC
1import $ from 'jquery';
2import annotator from 'annotator';
6cb364a2 3import { savePercent, retrievePercent, initFilters, initExport } from '../../_global/js/tools';
16ef7607
NL
4import './shortcuts/main.js';
5import './shortcuts/entry.js';
6cb364a2 6
af61cb80 7require('materialize'); // eslint-disable-line
6cb364a2 8
c146f694 9global.jQuery = $;
5ecdfcd0 10
c146f694 11$(document).ready(() => {
0743287f
TC
12 // sideNav
13 $('.button-collapse').sideNav();
14 $('select').material_select();
15 $('.collapsible').collapsible({
16 accordion: false,
17 });
18 $('.datepicker').pickadate({
19 selectMonths: true,
20 selectYears: 15,
21 formatSubmit: 'dd/mm/yyyy',
22 hiddenName: true,
23 format: 'dd/mm/yyyy',
24 });
25 initFilters();
26 initExport();
9948d899 27
c146f694 28 $('#nav-btn-add-tag').on('click', () => {
0743287f
TC
29 $('.nav-panel-add-tag').toggle(100);
30 $('.nav-panel-menu').addClass('hidden');
31 $('#tag_label').focus();
32 return false;
33 });
c146f694 34 $('#nav-btn-add').on('click', () => {
0743287f
TC
35 $('.nav-panel-buttom').hide(100);
36 $('.nav-panel-add').show(100);
37 $('.nav-panels .action').hide(100);
38 $('.nav-panel-menu').addClass('hidden');
39 $('.nav-panels').css('background', 'white');
40 $('#entry_url').focus();
41 return false;
42 });
c146f694 43 $('#nav-btn-search').on('click', () => {
0743287f
TC
44 $('.nav-panel-buttom').hide(100);
45 $('.nav-panel-search').show(100);
46 $('.nav-panels .action').hide(100);
47 $('.nav-panel-menu').addClass('hidden');
48 $('.nav-panels').css('background', 'white');
49 $('#searchfield').focus();
50 return false;
51 });
c146f694 52 $('.close').on('click', () => {
0743287f
TC
53 $('.nav-panel-add').hide(100);
54 $('.nav-panel-search').hide(100);
55 $('.nav-panel-buttom').show(100);
56 $('.nav-panels .action').show(100);
57 $('.nav-panel-menu').removeClass('hidden');
58 $('.nav-panels').css('background', 'transparent');
59 return false;
60 });
c146f694
TC
61 $(window).scroll(() => {
62 const s = $(window).scrollTop();
63 const d = $(document).height();
64 const c = $(window).height();
65 const scrollPercent = (s / (d - c)) * 100;
66 $('.progress .determinate').css('width', `${scrollPercent}%`);
0743287f
TC
67 });
68
69/* ==========================================================================
70 Annotations & Remember position
71 ========================================================================== */
5ecdfcd0 72
0743287f 73 if ($('article').length) {
c146f694
TC
74 const app = new annotator.App();
75 const x = JSON.parse($('#annotationroutes').html());
5ecdfcd0 76
0743287f
TC
77 app.include(annotator.ui.main, {
78 element: document.querySelector('article'),
79 });
5ecdfcd0 80
0743287f 81 app.include(annotator.storage.http, x);
5ecdfcd0 82
c146f694 83 app.start().then(() => {
0743287f
TC
84 app.annotations.load({ entry: x.entryId });
85 });
5ecdfcd0 86
c146f694
TC
87 $(window).scroll(() => {
88 const scrollTop = $(window).scrollTop();
89 const docHeight = $(document).height();
90 const scrollPercent = (scrollTop) / (docHeight);
91 const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
0743287f
TC
92 savePercent(x.entryId, scrollPercentRounded);
93 });
5ecdfcd0 94
0743287f 95 retrievePercent(x.entryId);
5ecdfcd0 96
c146f694 97 $(window).resize(() => {
0743287f
TC
98 retrievePercent(x.entryId);
99 });
100 }
d85454fb 101});