
ΜΟΝΟ ΣΤΟ ΣΗΜΕΡΙΝΟ ΜΑΚΕΛΕΙΟ! ΑΛΛΗΛΟΣΚ...

ΟΙ ΕΙΔΗΣΕΙΣ ΤΗΣ ΗΜΕΡΑΣ ΣΕ 60 ΔΕΥΤΕΡΟ...

ΣΤΑ ΚΑΓΚΕΛΑ Ο ΧΑΣΑΠΗΣ ΤΗΣ ΜΕΣΗΣ ΑΝΑΤ...

ΑΔΙΑΝΟΗΤΗ ΠΡΟΚΛΗΣΗ ΑΠΟ ΔΕΝΔΙΑ – ΔΥΟ ...

ΑΠΟ ΦΙΑΣΚΟ ΣΕ ΦΙΑΣΚΟ – ΚΑΜΠΑΝΑΚΙ ΑΠΟ...

ΘΡΗΝΟΣ ΓΙΑ ΤΗΝ ΕΛΛΗΝΙΚΗ ΔΙΠΛΩΜΑΤΙΑ –...

ΜΑ ΕΜΕΙΣ ΔΕΝ ΚΑΝΟΥΜΕ ΠΟΛΕΜΟ ΜΕ ΤΟΥΣ ...
';
wrapper.classList.add('active-video');
// Safety: destroy any previous
if (ytPlayers[idx] && typeof ytPlayers[idx].destroy === 'function') {
try { ytPlayers[idx].destroy(); } catch(e) {}
delete ytPlayers[idx];
}
ytPlayers[idx] = new YT.Player(playerId, {
height: '580',
width: '100%',
videoId: videoId,
playerVars: {
autoplay: 1,
mute: 1,
playsinline: 1,
rel: 0,
modestbranding: 1
},
events: {
onReady: function (event) {
try {
event.target.mute();
event.target.playVideo();
} catch (e) {}
},
onStateChange: function (event) {
// 0 = ended -> loop
if (event.data === 0) {
try {
event.target.seekTo(0, true);
event.target.playVideo();
} catch (e) {}
}
}
}
});
});
}
// Manual play button remains (click-to-play). For youtube we also use API path above.
function bindPlayButtons() {
document.querySelectorAll('.CustomPlayButton').forEach(button => {
button.addEventListener('click', (e) => {
e.stopPropagation();
const wrapper = button.closest('.CustomVideoWrapper');
if (!wrapper) return;
const type = wrapper.getAttribute('data-type');
let url = wrapper.getAttribute('data-url');
if (type === 'youtube') {
// Use same autoplay path (creates player) but keep UX
const slide = wrapper.closest('.slideCustom');
if (slide) autoplayYoutubeForSlide(slide);
return;
}
let iframeHTML = '';
if (type === 'rumble') {
iframeHTML = '
';
}
if (iframeHTML) {
wrapper.innerHTML = iframeHTML;
wrapper.classList.add('active-video');
}
});
});
}
function resetVideosToThumbnails() {
// For YouTube: pause but DO NOT replace markup (so it can resume)
document.querySelectorAll('.CustomVideoWrapper.active-video[data-type="youtube"]').forEach(wrapper => {
const slide = wrapper.closest('.slideCustom');
if (slide) pauseYoutubeForSlide(slide);
});
// For others: revert to thumbnail
document.querySelectorAll('.CustomVideoWrapper.active-video:not([data-type="youtube"])').forEach(wrapper => {
const image = wrapper.getAttribute('data-image');
const title = wrapper.getAttribute('data-title');
const thumbnailHTML =
'
' +
'

' +
'
' +
'' +
'
' +
'
';
wrapper.innerHTML = thumbnailHTML;
wrapper.classList.remove('active-video');
});
// Rumble lazy load (your existing logic)
document.querySelectorAll(".loadedRumble > .thumb-slider-wrap").forEach(function (el) {
let url = el.dataset.url;
let separator = url.includes("?") ? "&" : "?";
setTimeout(function () {
el.innerHTML = '
';
}, 500);
let parent = el.closest(".loadedRumble");
if (parent) parent.classList.remove("loadedRumble");
});
bindPlayButtons();
}
function updateSlider(index) {
// Pause previous active youtube so it can resume later
const prevActive = document.querySelector('.slideCustom.active');
if (prevActive) pauseYoutubeForSlide(prevActive);
sliderTrack.style.transform = 'translateX(-' + (index * 100) + '%)';
slides.forEach((slide, i) => {
slide.classList.toggle('active', i === index);
if (i === index && slide.classList.contains('slide_rumble')) {
setTimeout(function () { slide.classList.add('loadedRumble'); }, 500);
}
});
botItems.forEach((item, i) => {
item.classList.toggle('active', i === index);
});
// Reset non-youtube videos; youtube will pause and keep player
resetVideosToThumbnails();
// Autoplay/resume active youtube if slider is in view
const activeSlide = slides[index];
setTimeout(() => {
if (sliderInView) {
if (!resumeYoutubeForSlide(activeSlide)) autoplayYoutubeForSlide(activeSlide);
} else {
pauseYoutubeForSlide(activeSlide);
}
}, 150);
}
function moveSlide(direction) {
currentIndex += direction;
if (currentIndex = totalSlides) currentIndex = 0;
updateSlider(currentIndex);
resetInterval();
}
botItems.forEach((item, i) => {
item.addEventListener('click', () => {
currentIndex = i;
updateSlider(currentIndex);
resetInterval();
});
});
let autoSlide;
function resetInterval() {
clearInterval(autoSlide);
autoSlide = setInterval(() => {
// stop autoslide if a video is playing (youtube or other)
if ($('.slideCustom.active .CustomVideoWrapper.active-video').length === 0) {
moveSlide(1);
}
}, 8000);
}
function stopAutoSlide() { clearInterval(autoSlide); }
resetInterval();
$('.slideCustom').on('mouseenter', function () { stopAutoSlide(); });
$('.slideCustom').on('mouseleave', function () { resetInterval(); });
// Viewport observer: pause when out, resume when in
if (sliderContainer) {
const obs = new IntersectionObserver((entries) => {
entries.forEach(entry => {
sliderInView = entry.isIntersecting;
const activeSlide = slides[currentIndex];
if (!sliderInView) {
if (activeSlide) pauseYoutubeForSlide(activeSlide);
} else {
if (activeSlide) {
setTimeout(() => {
if (!resumeYoutubeForSlide(activeSlide)) autoplayYoutubeForSlide(activeSlide);
}, 150);
}
}
});
}, { threshold: [0, 0.1, 1] });
obs.observe(sliderContainer);
}
// Initial load (delay helps autoplay policies)
setTimeout(() => { updateSlider(currentIndex); }, 300);
bindPlayButtons();
})(jQuery);