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