demarches-normaliennes/app/javascript/new_design/spinner.js
2018-09-12 15:53:02 +02:00

16 lines
482 B
JavaScript

import Rails from 'rails-ujs';
import { show, hide } from '../shared/utils';
const { delegate } = Rails;
function showSpinner() {
[...document.querySelectorAll('.spinner')].forEach(show);
}
function hideSpinner() {
[...document.querySelectorAll('.spinner')].forEach(hide);
}
delegate(document, '[data-spinner]', 'ajax:complete', hideSpinner);
delegate(document, '[data-spinner]', 'ajax:stopped', hideSpinner);
delegate(document, '[data-spinner]', 'ajax:send', showSpinner);