2024-06-08 17:47:09 +02:00
|
|
|
import { assertNotNull } from './utils/assert';
|
|
|
|
import { $ } from './utils/dom';
|
2021-10-10 00:50:57 +02:00
|
|
|
import { inputDuplicatorCreator } from './input-duplicator';
|
2024-06-08 17:47:09 +02:00
|
|
|
import '../types/ujs';
|
2021-10-10 00:50:57 +02:00
|
|
|
|
2024-03-24 16:44:48 +01:00
|
|
|
function setupInputs() {
|
2021-10-10 00:50:57 +02:00
|
|
|
inputDuplicatorCreator({
|
|
|
|
addButtonSelector: '.js-image-add-source',
|
|
|
|
fieldSelector: '.js-image-source',
|
|
|
|
maxInputCountSelector: '.js-max-source-count',
|
|
|
|
removeButtonSelector: '.js-source-remove',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-08 17:47:09 +02:00
|
|
|
export function imageSourcesCreator() {
|
2024-03-24 16:44:48 +01:00
|
|
|
setupInputs();
|
|
|
|
|
2024-06-08 17:47:09 +02:00
|
|
|
document.addEventListener('fetchcomplete', ({ target, detail }) => {
|
2024-03-24 16:44:48 +01:00
|
|
|
if (target.matches('#source-form')) {
|
2024-06-08 17:47:09 +02:00
|
|
|
const sourceSauce = assertNotNull($<HTMLElement>('.js-sourcesauce'));
|
|
|
|
|
2024-03-24 16:44:48 +01:00
|
|
|
detail.text().then(text => {
|
|
|
|
sourceSauce.outerHTML = text;
|
|
|
|
setupInputs();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|