mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
32 lines
863 B
TypeScript
32 lines
863 B
TypeScript
import { $ } from './utils/dom';
|
|
import { inputDuplicatorCreator } from './input-duplicator';
|
|
|
|
export interface SourcesEvent extends CustomEvent<Response> {
|
|
target: HTMLElement,
|
|
}
|
|
|
|
function setupInputs() {
|
|
inputDuplicatorCreator({
|
|
addButtonSelector: '.js-image-add-source',
|
|
fieldSelector: '.js-image-source',
|
|
maxInputCountSelector: '.js-max-source-count',
|
|
removeButtonSelector: '.js-source-remove',
|
|
});
|
|
}
|
|
|
|
function imageSourcesCreator() {
|
|
setupInputs();
|
|
|
|
document.addEventListener('fetchcomplete', (({ target, detail }: SourcesEvent) => {
|
|
const sourceSauce = $<HTMLElement>('.js-sourcesauce');
|
|
|
|
if (sourceSauce && target && target.matches('#source-form')) {
|
|
detail.text().then(text => {
|
|
sourceSauce.outerHTML = text;
|
|
setupInputs();
|
|
});
|
|
}
|
|
}) as EventListener);
|
|
}
|
|
|
|
export { imageSourcesCreator };
|