mastodon/app/javascript/flavours/glitch/packs/settings.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

import 'packs/public-path';
import loadPolyfills from 'flavours/glitch/load_polyfills';
import ready from 'flavours/glitch/ready';
import loadKeyboardExtensions from 'flavours/glitch/load_keyboard_extensions';
import 'cocoon-js-vanilla';
2019-09-30 14:38:12 +00:00
function main() {
const { delegate } = require('@rails/ujs');
2019-09-30 14:38:12 +00:00
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');
};
2019-09-30 14:38:12 +00:00
delegate(document, '.sidebar__toggle__icon', 'click', () => {
toggleSidebar();
});
delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
toggleSidebar();
}
2019-09-30 14:38:12 +00:00
});
}
loadPolyfills()
.then(main)
.then(loadKeyboardExtensions)
.catch(error => {
console.error(error);
});