aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes/material/js
diff options
context:
space:
mode:
Diffstat (limited to 'app/Resources/static/themes/material/js')
-rwxr-xr-xapp/Resources/static/themes/material/js/init.js110
-rw-r--r--app/Resources/static/themes/material/js/tools.js24
2 files changed, 24 insertions, 110 deletions
diff --git a/app/Resources/static/themes/material/js/init.js b/app/Resources/static/themes/material/js/init.js
deleted file mode 100755
index 0b2832c0..00000000
--- a/app/Resources/static/themes/material/js/init.js
+++ /dev/null
@@ -1,110 +0,0 @@
1/* jQuery */
2import $ from 'jquery';
3
4/* Annotations */
5import annotator from 'annotator';
6
7/* Tools */
8import { savePercent, retrievePercent, initFilters, initExport } from '../../_global/js/tools';
9
10/* Import shortcuts */
11import './shortcuts/main';
12import './shortcuts/entry';
13import '../../_global/js/shortcuts/main';
14import '../../_global/js/shortcuts/entry';
15
16require('materialize'); // eslint-disable-line
17
18global.jQuery = $;
19
20$(document).ready(() => {
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();
36
37 $('#nav-btn-add-tag').on('click', () => {
38 $('.nav-panel-add-tag').toggle(100);
39 $('.nav-panel-menu').addClass('hidden');
40 $('#tag_label').focus();
41 return false;
42 });
43 $('#nav-btn-add').on('click', () => {
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 });
52 $('#nav-btn-search').on('click', () => {
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 $('#search_entry_term').focus();
59 return false;
60 });
61 $('.close').on('click', () => {
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 });
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}%`);
76 });
77
78/* ==========================================================================
79 Annotations & Remember position
80 ========================================================================== */
81
82 if ($('article').length) {
83 const app = new annotator.App();
84 const x = JSON.parse($('#annotationroutes').html());
85
86 app.include(annotator.ui.main, {
87 element: document.querySelector('article'),
88 });
89
90 app.include(annotator.storage.http, x);
91
92 app.start().then(() => {
93 app.annotations.load({ entry: x.entryId });
94 });
95
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;
101 savePercent(x.entryId, scrollPercentRounded);
102 });
103
104 retrievePercent(x.entryId);
105
106 $(window).resize(() => {
107 retrievePercent(x.entryId);
108 });
109 }
110});
diff --git a/app/Resources/static/themes/material/js/tools.js b/app/Resources/static/themes/material/js/tools.js
new file mode 100644
index 00000000..39398fd8
--- /dev/null
+++ b/app/Resources/static/themes/material/js/tools.js
@@ -0,0 +1,24 @@
1import $ from 'jquery';
2
3function initFilters() {
4 // no display if filters not available
5 if ($('div').is('#filters')) {
6 $('#button_filters').show();
7 $('.js-filters-action').sideNav({ edge: 'right' });
8 $('#clear_form_filters').on('click', () => {
9 $('#filters input').val('');
10 $('#filters :checked').removeAttr('checked');
11 return false;
12 });
13 }
14}
15
16function initExport() {
17 // no display if export not available
18 if ($('div').is('#export')) {
19 $('#button_export').show();
20 $('.js-export-action').sideNav({ edge: 'right' });
21 }
22}
23
24export { initExport, initFilters };