]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/material/index.js
Side nav hidden on mobile tag adding
[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
a5ac6046
S
20const mobileMaxWidth = 993;
21
cfd77d1c
S
22const stickyNav = () => {
23 const nav = $('.js-entry-nav-top');
24 $('[data-toggle="actions"]').click(() => {
25 nav.toggleClass('entry-nav-top--sticky');
26 });
27};
28
dc23bf9f
S
29const articleScroll = () => {
30 const articleEl = $('#article');
31 if (articleEl.length > 0) {
32 $(window).scroll(() => {
33 const s = $(window).scrollTop();
34 const d = $(document).height();
35 const c = $(window).height();
36 const articleElBottom = articleEl.offset().top + articleEl.height();
37 const scrollPercent = (s / (d - c)) * 100;
38 $('.progress .determinate').css('width', `${scrollPercent}%`);
39 const fixedActionBtn = $('.js-fixed-action-btn');
40 const toggleScrollDataName = 'toggle-auto';
41 if ((s + c) > articleElBottom) {
42 fixedActionBtn.data(toggleScrollDataName, true);
43 fixedActionBtn.openFAB();
44 } else if (fixedActionBtn.data(toggleScrollDataName) === true) {
45 fixedActionBtn.data(toggleScrollDataName, false);
46 fixedActionBtn.closeFAB();
47 }
48 });
49 }
50};
51
c146f694 52$(document).ready(() => {
0743287f
TC
53 // sideNav
54 $('.button-collapse').sideNav();
55 $('select').material_select();
56 $('.collapsible').collapsible({
57 accordion: false,
58 });
59 $('.datepicker').pickadate({
60 selectMonths: true,
61 selectYears: 15,
8ee7b160
KD
62 formatSubmit: 'yyyy-mm-dd',
63 hiddenName: false,
64 format: 'yyyy-mm-dd',
64f81bc3 65 container: 'body',
0743287f 66 });
50f35f0d 67
d9a68f6c
NL
68 $('.dropdown-trigger').dropdown({ hover: false });
69
0743287f
TC
70 initFilters();
71 initExport();
50f35f0d 72 initRandom();
cfd77d1c 73 stickyNav();
dc23bf9f 74 articleScroll();
9948d899 75
91f59924
S
76 const toggleNav = (toShow, toFocus) => {
77 $('.nav-panel-actions').hide(100);
78 $(toShow).show(100);
79 $('.nav-panels').css('background', 'white');
80 $(toFocus).focus();
81 };
82
c146f694 83 $('#nav-btn-add-tag').on('click', () => {
0743287f
TC
84 $('.nav-panel-add-tag').toggle(100);
85 $('.nav-panel-menu').addClass('hidden');
a5ac6046
S
86 if (window.innerWidth < mobileMaxWidth) {
87 $('.side-nav').sideNav('hide');
88 }
0743287f
TC
89 $('#tag_label').focus();
90 return false;
91 });
a6b242a1 92
c146f694 93 $('#nav-btn-add').on('click', () => {
91f59924 94 toggleNav('.nav-panel-add', '#entry_url');
0743287f
TC
95 return false;
96 });
a6b242a1 97
2831e77c 98 const materialAddForm = $('.nav-panel-add');
3d46eeeb
KD
99 materialAddForm.on('submit', () => {
100 materialAddForm.addClass('disabled');
101 $('input#entry_url', materialAddForm).prop('readonly', true).trigger('blur');
102 });
a6b242a1 103
c146f694 104 $('#nav-btn-search').on('click', () => {
91f59924 105 toggleNav('.nav-panel-search', '#search_entry_term');
0743287f
TC
106 return false;
107 });
a6b242a1 108
91f59924
S
109 $('.close').on('click', (e) => {
110 $(e.target).parent('.nav-panel-item').hide(100);
2831e77c 111 $('.nav-panel-actions').show(100);
0743287f
TC
112 $('.nav-panels').css('background', 'transparent');
113 return false;
114 });
46732777
NL
115
116 const mainCheckboxes = document.querySelectorAll('[data-js="checkboxes-toggle"]');
117 if (mainCheckboxes.length) {
118 [...mainCheckboxes].forEach((el) => {
119 el.addEventListener('click', () => {
120 const checkboxes = document.querySelectorAll(el.dataset.toggle);
121 [...checkboxes].forEach((checkbox) => {
122 const checkboxClone = checkbox;
123 checkboxClone.checked = el.checked;
124 });
125 });
126 });
127 }
d85454fb 128});