This commit is contained in:
Philippe Torrel
2026-07-22 09:08:51 +02:00
parent 1c64e896e4
commit b3f884d650
1006 changed files with 3015 additions and 201756 deletions

View File

@@ -2,16 +2,54 @@
(() => {
// === DOM & VARS =======
const DOM = {};
const module = document.querySelector('.m-cutey-cat') || console.error('Element: ".m-cutey-cat" not found');
if (!module) return;
const DOM = {
listItemsCatVote: Array.from(module.querySelectorAll('.list-cat-vote li')),
listCatSelection: module.querySelector('.list-cat-selection'),
};
// console.log(module);
// console.log('listItemsCatVote: ', DOM.listItemsCatVote);
// console.log('listCatSelection', DOM.listCatSelection);
// === INIT =============
const init = () => {};
const init = () => {
// Eventhandler für die vorhandenen Katzen
DOM.listItemsCatVote.forEach((el) => {
el.addEventListener('click', onClickCatVoteAdd);
});
};
// === EVENTHANDLER =====
const onClickCatVoteAdd = (e) => {
const selCat = e.currentTarget.cloneNode(true);
const altSelCat = selCat.querySelector('img').alt;
//console.log(DOM.listCatSelection.childElementCount);
// Guard
if (isCastInSelection(altSelCat) || DOM.listCatSelection.childElementCount === 3) return;
// if (!isCastInSelection(altSelCat) && DOM.listCatSelection.childElementCount < 3) {
selCat.addEventListener('click', onClickCatSelRemove);
DOM.listCatSelection.appendChild(selCat);
// }
};
const onClickCatSelRemove = (e) => {
e.currentTarget.remove();
};
// === XHR/FETCH ========
// === FUNCTIONS ========
const isCastInSelection = (alt) => {
const votedCats = Array.from(DOM.listCatSelection.querySelectorAll('li img'));
return votedCats.some((el) => alt === el.alt);
};
init();
})();