mastodon/app/javascript/flavours/glitch/packs/settings.js
Renaud Chaput 108720d7b0 [Glitch] Dont use CommonJS (require, module.exports) anywhere
Port 955179fc55 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2023-05-09 22:28:53 +02:00

42 lines
1.1 KiB
JavaScript

import 'packs/public-path';
import loadPolyfills from 'flavours/glitch/load_polyfills';
import loadKeyboardExtensions from 'flavours/glitch/load_keyboard_extensions';
import { delegate } from '@rails/ujs';
import 'cocoon-js-vanilla';
function main() {
const toggleSidebar = () => {
const sidebar = document.querySelector('.sidebar ul');
const toggleButton = document.querySelector('.sidebar__toggle__icon');
if (sidebar.classList.contains('visible')) {
document.body.style.overflow = null;
toggleButton.setAttribute('aria-expanded', 'false');
} else {
document.body.style.overflow = 'hidden';
toggleButton.setAttribute('aria-expanded', 'true');
}
toggleButton.classList.toggle('active');
sidebar.classList.toggle('visible');
};
delegate(document, '.sidebar__toggle__icon', 'click', () => {
toggleSidebar();
});
delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
toggleSidebar();
}
});
}
loadPolyfills()
.then(main)
.then(loadKeyboardExtensions)
.catch(error => {
console.error(error);
});