Run load scripts after ujs responces
This commit is contained in:
parent
c370b61abd
commit
86b9ed2079
11 changed files with 20 additions and 18 deletions
|
@ -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)]);
|
||||
|
|
|
@ -20,8 +20,7 @@ function init() {
|
|||
}
|
||||
}
|
||||
|
||||
addEventListener('DOMContentLoaded', init);
|
||||
addEventListener('turbolinks:load', init);
|
||||
addEventListener('ds:page:update', init);
|
||||
|
||||
function toggleElement(event) {
|
||||
event.preventDefault();
|
||||
|
|
9
app/javascript/shared/page-update-event.js
Normal file
9
app/javascript/shared/page-update-event.js
Normal 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');
|
||||
});
|
2
app/javascript/shared/react-ujs.js
vendored
2
app/javascript/shared/react-ujs.js
vendored
|
@ -56,6 +56,6 @@ export default class ReactUJS {
|
|||
}
|
||||
|
||||
start() {
|
||||
addEventListener('turbolinks:load', () => this.mountComponents());
|
||||
addEventListener('ds:page:update', () => this.mountComponents());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue