mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 20:37:59 +01:00
32 lines
867 B
TypeScript
32 lines
867 B
TypeScript
import { $ } from './utils/dom';
|
|
import { inputDuplicatorCreator } from './input-duplicator';
|
|
|
|
export interface TagSourceEvent 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 }: TagSourceEvent) => {
|
|
const sourceSauce = $<HTMLElement>('.js-sourcesauce');
|
|
|
|
if (sourceSauce && target && target.matches('#source-form')) {
|
|
detail.text().then(text => {
|
|
sourceSauce.outerHTML = text;
|
|
setupInputs();
|
|
});
|
|
}
|
|
}) as EventListener);
|
|
}
|
|
|
|
export { imageSourcesCreator };
|