Banner Home (FR)
16 Déc 2016

/* ================================================== PAGE INITIALISATION ================================================== */
document.addEventListener('DOMContentLoaded', function () {
const isMobile = window.matchMedia('(max-width: 768px)').matches;
const video = document.getElementById('heroVideo');
/* ================================================ MOBILE Remove video source so it doesn't keep loading. ================================================= */
if (isMobile && video) {
video.pause();
video.removeAttribute('autoplay');
const sources = video.querySelectorAll('source');
sources.forEach(function (source) {
source.removeAttribute('src');
});
video.load();
return; }
/* ================================================ DESKTOP VIDEO ================================================= */
if (video) {
video.muted = true;
const playPromise = video.play();
if (playPromise !== undefined) {
playPromise.catch(function () {
/* Browser may block autoplay */
});
}
}
});
/* ================================================== AUDIO
The MP3 does NOT exist in the page source initially.
ONLY after the visitor clicks the button do we: 1. Add the audio URL 2. Load it 3. Play it ================================================== */
function toggleAudio() {
const audio = document.getElementById('heroAudio');
const audioIcon = document.getElementById('audioIcon');
if (!audio || !audioIcon) { return; }
/* ----------------------------------------------- FIRST CLICK: Assign the MP3 only now ------------------------------------------------ */
if (!audio.getAttribute('src')) {
audio.src = 'http://www.riad-anata.com/wp-content/uploads/2025/06/video_riad-anata_home_audio.mp3';
audio.volume = 0.5;
audio.play() .then(function () {
setSoundOnIcon();
}) .catch(function (error) {
console.log('Audio playback blocked:', error);
});
return; }
/* ----------------------------------------------- FOLLOWING CLICKS: Play / Pause ------------------------------------------------ */
if (audio.paused) {
audio.play() .then(function () {
setSoundOnIcon();
}) .catch(function (error) {
console.log('Audio playback blocked:', error);
});
}
else {
audio.pause();
setSoundOffIcon();
}
}
/* ================================================== SOUND ON ICON ================================================== */
function setSoundOnIcon() {
const audioIcon = document.getElementById('audioIcon');
if (!audioIcon) { return; }
audioIcon.src = 'http://www.riad-anata.com/wp-content/uploads/2025/06/icons8-speaker-50.png';
audioIcon.alt = 'Sound On';
}
/* ================================================== SOUND OFF ICON ================================================== */
function setSoundOffIcon() {
const audioIcon = document.getElementById('audioIcon');
if (!audioIcon) { return; }
audioIcon.src = 'http://www.riad-anata.com/wp-content/uploads/2025/06/icons8-speaker-off-50.png';
audioIcon.alt = 'Sound Off';
}
Share this story
