2024-06-06 18:48:16 +02:00
|
|
|
import { $ } from './utils/dom';
|
2021-10-10 00:50:57 +02:00
|
|
|
import { inputDuplicatorCreator } from './input-duplicator';
|
|
|
|
|
2024-06-10 23:20:44 +02:00
|
|
|
export interface TagSourceEvent extends CustomEvent<Response> {
|
2024-06-06 18:48:16 +02:00
|
|
|
target: HTMLElement,
|
|
|
|
}
|
|
|
|
|
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-03-24 16:44:48 +01:00
|
|
|
function imageSourcesCreator() {
|
|
|
|
setupInputs();
|
|
|
|
|
2024-06-10 23:20:44 +02:00
|
|
|
document.addEventListener('fetchcomplete', (({ target, detail }: TagSourceEvent) => {
|
2024-06-06 18:48:16 +02:00
|
|
|
const sourceSauce = $<HTMLElement>('.js-sourcesauce');
|
|
|
|
|
|
|
|
if (sourceSauce && target && target.matches('#source-form')) {
|
2024-03-24 16:44:48 +01:00
|
|
|
detail.text().then(text => {
|
|
|
|
sourceSauce.outerHTML = text;
|
|
|
|
setupInputs();
|
|
|
|
});
|
|
|
|
}
|
2024-06-06 18:48:16 +02:00
|
|
|
}) as EventListener);
|
2024-03-24 16:44:48 +01:00
|
|
|
}
|
|
|
|
|
2021-10-10 00:50:57 +02:00
|
|
|
export { imageSourcesCreator };
|