Run load scripts after ujs responces (#4170)

Exécute les scripts UJS après une modification asynchrone de la page
This commit is contained in:
Pierre de La Morinerie 2019-08-13 19:47:29 +02:00 committed by GitHub
commit e6c5b24bcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 20 additions and 18 deletions

View file

@ -39,7 +39,7 @@ function diplayMap(element, data, initial = false) {
}
}
addEventListener('turbolinks:load', initialize);
addEventListener('ds:page:update', initialize);
addEventListener('carte:update', ({ detail: { selector, data } }) => {
const element = document.querySelector(selector);

View file

@ -14,4 +14,4 @@ export function scrollMessagerie() {
}
}
addEventListener('turbolinks:load', scrollMessagerie);
addEventListener('ds:page:update', scrollMessagerie);

View file

@ -14,7 +14,7 @@ function expandProcedureDescription() {
descBody.classList.remove('read-more-collapsed');
}
addEventListener('turbolinks:load', updateReadMoreVisibility);
addEventListener('ds:page:update', updateReadMoreVisibility);
addEventListener('resize', updateReadMoreVisibility);
delegate('click', '.read-more-button', expandProcedureDescription);

View file

@ -1,7 +1,7 @@
import $ from 'jquery';
import 'select2';
addEventListener('turbolinks:load', () => {
addEventListener('ds:page:update', () => {
$('select.select2').select2({
language: 'fr',
width: '100%'

View file

@ -12,5 +12,5 @@ function updateContactElementsVisibility() {
}
}
addEventListener('turbolinks:load', updateContactElementsVisibility);
addEventListener('ds:page:update', updateContactElementsVisibility);
delegate('change', '#contact-form #type', updateContactElementsVisibility);

View file

@ -4,6 +4,7 @@ import Rails from '@rails/ujs';
import * as ActiveStorage from '@rails/activestorage';
import jQuery from 'jquery';
import '../shared/page-update-event';
import '../shared/activestorage/ujs';
import '../shared/rails-ujs-fix';
import '../shared/safari-11-file-xhr-workaround';

View file

@ -9,6 +9,7 @@ import Highcharts from 'highcharts';
import ReactUJS from '../shared/react-ujs';
import reactComponents from '../shared/react-components';
import '../shared/page-update-event';
import '../shared/activestorage/ujs';
import '../shared/activestorage/attachment-checker';
import '../shared/rails-ujs-fix';

View file

@ -37,22 +37,14 @@ function source(url) {
};
}
addEventListener('turbolinks:load', function() {
autocompleteSetup();
});
addEventListener('ajax:success', function() {
autocompleteSetup();
});
function autocompleteSetup() {
addEventListener('ds:page:update', function() {
for (let { type, url } of sources) {
for (let element of document.querySelectorAll(selector(type))) {
element.removeAttribute('data-autocomplete');
autocompleteInitializeElement(element, url);
}
}
}
});
function autocompleteInitializeElement(element, url) {
const select = autocomplete(element, options, [source(url)]);

View file

@ -20,8 +20,7 @@ function init() {
}
}
addEventListener('DOMContentLoaded', init);
addEventListener('turbolinks:load', init);
addEventListener('ds:page:update', init);
function toggleElement(event) {
event.preventDefault();

View file

@ -0,0 +1,9 @@
import { fire } from '@utils';
addEventListener('turbolinks:load', function() {
fire(document, 'ds:page:update');
});
addEventListener('ajax:success', function() {
fire(document, 'ds:page:update');
});

View file

@ -56,6 +56,6 @@ export default class ReactUJS {
}
start() {
addEventListener('turbolinks:load', () => this.mountComponents());
addEventListener('ds:page:update', () => this.mountComponents());
}
}