javascript: make utils resilient to missing elements (#4546)

Javascript : les fonctions utilitaires fonctionnent lorsque l'élément n'existe pas
This commit is contained in:
Pierre de La Morinerie 2019-11-20 17:41:51 +01:00 committed by GitHub
commit 0b8512362e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,16 +5,16 @@ import debounce from 'debounce';
export { debounce };
export const { fire, ajax } = Rails;
export function show({ classList }) {
classList.remove('hidden');
export function show(el) {
el && el.classList.remove('hidden');
}
export function hide({ classList }) {
classList.add('hidden');
export function hide(el) {
el && el.classList.add('hidden');
}
export function toggle({ classList }) {
classList.toggle('hidden');
export function toggle(el) {
el && el.classList.toggle('hidden');
}
export function delegate(eventNames, selector, callback) {