|
|
|
@ -3,10 +3,24 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
const right = document.querySelector('.right-emoji');
|
|
|
|
|
const winnerText = document.getElementById('winner-text');
|
|
|
|
|
|
|
|
|
|
// These variables will be injected by Twig in the template as data attributes or global variables
|
|
|
|
|
const winnerSide = window.winnerSide;
|
|
|
|
|
const loserSide = window.loserSide;
|
|
|
|
|
|
|
|
|
|
function insertEmojiOrImage(el) {
|
|
|
|
|
const value = el.dataset.content;
|
|
|
|
|
if (/^https?:\/\//.test(value)) {
|
|
|
|
|
const img = document.createElement('img');
|
|
|
|
|
img.src = value;
|
|
|
|
|
img.className = 'emoji-img';
|
|
|
|
|
el.appendChild(img);
|
|
|
|
|
} else {
|
|
|
|
|
el.textContent = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertEmojiOrImage(left);
|
|
|
|
|
insertEmojiOrImage(right);
|
|
|
|
|
|
|
|
|
|
left.classList.add('slide-in-left');
|
|
|
|
|
right.classList.add('slide-in-right');
|
|
|
|
|
|
|
|
|
@ -31,7 +45,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
const winner = winnerSide === 'left' ? left : right;
|
|
|
|
|
winner.classList.add('winner-center', 'winner-crown');
|
|
|
|
|
|
|
|
|
|
winnerText.textContent = `${winner.textContent.trim()} a gagné ! 🎉`;
|
|
|
|
|
let name = winner.dataset.content;
|
|
|
|
|
//check if name is an image URL or an emoji
|
|
|
|
|
if (/^https?:\/\//.test(name)) {
|
|
|
|
|
winnerText.innerHTML = `<img src="${name}" style="width:64px">a gagné ! 🎉`;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
winnerText.textContent = `${name} a gagné ! 🎉`;
|
|
|
|
|
}
|
|
|
|
|
winnerText.style.display = 'block';
|
|
|
|
|
}, 1500);
|
|
|
|
|
}, 3000);
|
|
|
|
|