]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/material/index.js
First draft
[github/wallabag/wallabag.git] / app / Resources / static / themes / material / index.js
CommitLineData
af61cb80 1import $ from 'jquery';
5637a26e 2
64f81bc3
TC
3/* Materialize imports */
4import 'materialize-css/dist/css/materialize.css';
5import 'materialize-css/dist/js/materialize';
6
7/* Global imports */
8import '../_global/index';
5637a26e
TC
9
10/* Tools */
50f35f0d 11import { initExport, initFilters, initRandom } from './js/tools';
5637a26e
TC
12
13/* Import shortcuts */
64f81bc3
TC
14import './js/shortcuts/main';
15import './js/shortcuts/entry';
6cb364a2 16
64f81bc3
TC
17/* Theme style */
18import './css/index.scss';
5ecdfcd0 19
cfd77d1c
S
20const stickyNav = () => {
21 const nav = $('.js-entry-nav-top');
22 $('[data-toggle="actions"]').click(() => {
23 nav.toggleClass('entry-nav-top--sticky');
24 });
25};
26
dc23bf9f
S
27const articleScroll = () => {
28 const articleEl = $('#article');
29 if (articleEl.length > 0) {
30 $(window).scroll(() => {
31 const s = $(window).scrollTop();
32 const d = $(document).height();
33 const c = $(window).height();
34 const articleElBottom = articleEl.offset().top + articleEl.height();
35 const scrollPercent = (s / (d - c)) * 100;
36 $('.progress .determinate').css('width', `${scrollPercent}%`);
37 const fixedActionBtn = $('.js-fixed-action-btn');
38 const toggleScrollDataName = 'toggle-auto';
39 if ((s + c) > articleElBottom) {
40 fixedActionBtn.data(toggleScrollDataName, true);
41 fixedActionBtn.openFAB();
42 } else if (fixedActionBtn.data(toggleScrollDataName) === true) {
43 fixedActionBtn.data(toggleScrollDataName, false);
44 fixedActionBtn.closeFAB();
45 }
46 });
47 }
48};
49
c146f694 50$(document).ready(() => {
0743287f
TC
51 // sideNav
52 $('.button-collapse').sideNav();
53 $('select').material_select();
54 $('.collapsible').collapsible({
55 accordion: false,
56 });
57 $('.datepicker').pickadate({
58 selectMonths: true,
59 selectYears: 15,
8ee7b160
KD
60 formatSubmit: 'yyyy-mm-dd',
61 hiddenName: false,
62 format: 'yyyy-mm-dd',
64f81bc3 63 container: 'body',
0743287f 64 });
50f35f0d 65
d9a68f6c
NL
66 $('.dropdown-trigger').dropdown({ hover: false });
67
0743287f
TC
68 initFilters();
69 initExport();
50f35f0d 70 initRandom();
cfd77d1c 71 stickyNav();
dc23bf9f 72 articleScroll();
9948d899 73
91f59924
S
74 const toggleNav = (toShow, toFocus) => {
75 $('.nav-panel-actions').hide(100);
76 $(toShow).show(100);
77 $('.nav-panels').css('background', 'white');
78 $(toFocus).focus();
79 };
80
c146f694 81 $('#nav-btn-add-tag').on('click', () => {
0743287f
TC
82 $('.nav-panel-add-tag').toggle(100);
83 $('.nav-panel-menu').addClass('hidden');
84 $('#tag_label').focus();
85 return false;
86 });
a6b242a1 87
c146f694 88 $('#nav-btn-add').on('click', () => {
91f59924 89 toggleNav('.nav-panel-add', '#entry_url');
0743287f
TC
90 return false;
91 });
a6b242a1 92
2831e77c 93 const materialAddForm = $('.nav-panel-add');
3d46eeeb
KD
94 materialAddForm.on('submit', () => {
95 materialAddForm.addClass('disabled');
96 $('input#entry_url', materialAddForm).prop('readonly', true).trigger('blur');
97 });
a6b242a1 98
c146f694 99 $('#nav-btn-search').on('click', () => {
91f59924 100 toggleNav('.nav-panel-search', '#search_entry_term');
0743287f
TC
101 return false;
102 });
a6b242a1 103
91f59924
S
104 $('.close').on('click', (e) => {
105 $(e.target).parent('.nav-panel-item').hide(100);
2831e77c 106 $('.nav-panel-actions').show(100);
0743287f
TC
107 $('.nav-panels').css('background', 'transparent');
108 return false;
109 });
46732777
NL
110
111 const mainCheckboxes = document.querySelectorAll('[data-js="checkboxes-toggle"]');
112 if (mainCheckboxes.length) {
113 [...mainCheckboxes].forEach((el) => {
114 el.addEventListener('click', () => {
115 const checkboxes = document.querySelectorAll(el.dataset.toggle);
116 [...checkboxes].forEach((checkbox) => {
117 const checkboxClone = checkbox;
118 checkboxClone.checked = el.checked;
119 });
120 });
121 });
122 }
e101052a
NL
123
124 $('.markasread').on('click', () => {
125 const article = document.getElementById('article');
126 const link = document.getElementById('link-archive');
127 const articleId = article.dataset.id;
128 const xhr = new XMLHttpRequest();
129
130 xhr.onload = function toggleArchive() {
131 if (xhr.status === 200) {
132 const previousStatus = document.getElementById('archive-icon').innerHTML;
133 let status = link.dataset.iconUnread;
134 let label = link.dataset.labelUnread;
135 if (previousStatus === 'unarchive') {
136 status = link.dataset.iconRead;
137 label = link.dataset.labelRead;
138 }
139 document.getElementById('archive-icon').innerHTML = status;
140 document.getElementById('archive-label').innerHTML = label;
141 window.Materialize.toast(xhr.responseText, 4000);
142 }
143 };
144
145 const url = `${Routing.generate('archive_entry', { id: articleId })}?some_var_name=true`;
146 xhr.open('GET', url, false);
147 xhr.send(null);
148 });
d85454fb 149});