/* ==================================================
MA CONCIERGERIE 34
JAVASCRIPT GLOBAL V12
POP-UP + MAISON + SCROLL + NETTOYAGE
================================================== */
(function() {
"use strict";
if (window.__mc34GlobalV12) return;
window.__mc34GlobalV12 = true;
const reduced = window.matchMedia(
"(prefers-reduced-motion: reduce)"
);
function init() {
/* 01 - NETTOYAGE DES ANCIENS EFFETS */
if (
typeof window.mc34EffectsV8Cleanup === "function"
) {
window.mc34EffectsV8Cleanup();
}
if (
typeof window.mc34RevealV10Cleanup === "function"
) {
window.mc34RevealV10Cleanup();
}
[
"mc34-effects-v8",
"mc34-effects-v7",
"mc34-floating-photos-v1",
"mc34-white-glow-v1",
"mc34-side-gallery",
"mc34-side-gallery-v5",
"mc34-side-gallery-v9"
].forEach(function(id) {
document.getElementById(id)?.remove();
});
document.querySelectorAll(
'[id^="mc34-side-gallery"]'
).forEach(function(el) {
el.remove();
});
/* 02 - CRÉATION DU POP-UP */
document.getElementById("mc24-exit")?.remove();
const popup = document.createElement("div");
popup.id = "mc24-exit";
popup.setAttribute("aria-hidden", "true");
popup.innerHTML = `
MA CONCIERGERIE 34®
MONTPELLIER / 034
01 / UNE DERNIÈRE CHOSE
AVANT
DE PARTIR.
`;
document.body.appendChild(popup);
/* 03 - OUVERTURE ET FERMETURE */
let opened = false;
let closing = false;
let interacted = false;
let previousOverflow = "";
let previousFocus = null;
let closeTimer = null;
function showPopup() {
if (opened || closing) return;
try {
if (
sessionStorage.getItem("mc34V24Seen")
) {
return;
}
sessionStorage.setItem(
"mc34V24Seen",
"1"
);
} catch(e) {}
opened = true;
previousFocus = document.activeElement;
previousOverflow =
document.body.style.overflow;
document.body.style.overflow = "hidden";
popup.classList.add("open");
popup.setAttribute("aria-hidden", "false");
requestAnimationFrame(function() {
popup.classList.add("active");
});
popup.querySelector(".mc24-close")
.focus({ preventScroll: true });
}
function hidePopup() {
if (!opened) return;
opened = false;
closing = true;
popup.classList.remove("active");
popup.setAttribute("aria-hidden", "true");
document.body.style.overflow =
previousOverflow;
clearTimeout(closeTimer);
closeTimer = setTimeout(function() {
popup.classList.remove("open");
closing = false;
if (previousFocus?.focus) {
previousFocus.focus({
preventScroll: true
});
}
}, 350);
}
/* 04 - BOUTONS DU POP-UP */
popup.querySelector(".mc24-close")
.addEventListener("click", hidePopup);
popup.querySelector(".mc24-skip")
.addEventListener("click", hidePopup);
popup.querySelector(".mc24-overlay")
.addEventListener("click", hidePopup);
popup.querySelector(".mc24-cta")
.addEventListener("click", function(e) {
e.preventDefault();
hidePopup();
setTimeout(function() {
const target = document.getElementById(
"formulaire-devis"
);
if (target) {
target.scrollIntoView({
behavior: reduced.matches
? "auto"
: "smooth",
block: "start"
});
} else {
window.location.assign(
"https://maconciergerie34.fr/#formulaire-devis"
);
}
}, 380);
});
/* 05 - DÉTECTION DE SORTIE */
document.addEventListener(
"pointermove",
function() {
interacted = true;
},
{ passive: true, once: true }
);
document.addEventListener(
"mouseout",
function(e) {
if (e.relatedTarget || e.toElement) {
return;
}
if (e.clientY > 20) return;
if (!interacted) return;
if (window.scrollY < 50) return;
showPopup();
}
);
/* 06 - ACCESSIBILITÉ CLAVIER */
document.addEventListener(
"keydown",
function(e) {
if (!opened) return;
if (e.key === "Escape") {
hidePopup();
return;
}
if (e.key !== "Tab") return;
const items = Array.from(
popup.querySelectorAll(
"a[href],button:not([disabled])"
)
);
if (!items.length) return;
const first = items[0];
const last = items[items.length - 1];
if (
e.shiftKey &&
document.activeElement === first
) {
e.preventDefault();
last.focus();
} else if (
!e.shiftKey &&
document.activeElement === last
) {
e.preventDefault();
first.focus();
}
}
);
/* PRÉVISUALISATION MANUELLE */
window.mc34PreviewV24 = function() {
try {
sessionStorage.removeItem(
"mc34V24Seen"
);
} catch(e) {}
showPopup();
};
/* 07 - MAISON ANIMÉE */
const panel = popup.querySelector(
".mc24-panel"
);
const house = document.createElement("div");
house.id = "mc34-house-follow-v1";
house.setAttribute("aria-hidden", "true");
house.innerHTML = `
`;
panel.insertBefore(
house,
panel.firstChild
);
let houseX = 0;
let houseY = 0;
let targetX = 0;
let targetY = 0;
let houseFrame = 0;
let houseSteps = 0;
function moveHouse() {
houseX += (targetX - houseX) * .16;
houseY += (targetY - houseY) * .16;
house.style.transform =
"translate3d(calc(-50% + " +
houseX.toFixed(1) +
"px),calc(-50% + " +
houseY.toFixed(1) +
"px),0) rotate(" +
(houseX * .06).toFixed(2) +
"deg)";
houseSteps++;
if (
houseSteps < 45 &&
popup.classList.contains("open") &&
!reduced.matches
) {
houseFrame =
requestAnimationFrame(moveHouse);
} else {
houseFrame = 0;
}
}
panel.addEventListener(
"pointermove",
function(e) {
if (reduced.matches) return;
const rect =
panel.getBoundingClientRect();
targetX =
((e.clientX - rect.left) /
rect.width - .5) * 90;
targetY =
((e.clientY - rect.top) /
rect.height - .5) * 65;
houseSteps = 0;
if (!houseFrame) {
houseFrame =
requestAnimationFrame(moveHouse);
}
},
{ passive: true }
);
/* 08 - ANIMATIONS AU DÉFILEMENT */
const excluded = [
"#mc24-exit",
"#mc34-photo-home",
"header",
"nav",
"footer",
"form",
"[role='dialog']",
".leaflet-container",
"[data-mc34-no-reveal]"
].join(",");
const selector = [
"main section",
"main article",
".custom-html-section",
"[class*='custom-html']",
"[id^='mc34-']"
].join(",");
const observed = new WeakSet();
let observer = null;
function showReveal(el) {
el.classList.remove(
"mc34-v10-hidden"
);
el.classList.add(
"mc34-v10-visible"
);
}
function registerReveal(el) {
if (!(el instanceof HTMLElement)) {
return;
}
if (el.closest(excluded)) return;
if (el.matches(
"script,style,canvas,svg,button,a,input,textarea,select"
)) return;
if (observed.has(el)) return;
const rect =
el.getBoundingClientRect();
if (
rect.width < 30 ||
rect.height < 15
) return;
if (
el.parentElement?.closest(
".mc34-v10-reveal"
)
) return;
observed.add(el);
el.classList.add(
"mc34-v10-reveal"
);
if (
reduced.matches ||
!observer ||
rect.top < window.innerHeight ||
rect.bottom < 0
) {
showReveal(el);
return;
}
el.classList.add(
"mc34-v10-hidden"
);
observer.observe(el);
}
function scanReveal() {
document.querySelectorAll(selector)
.forEach(registerReveal);
}
if (
"IntersectionObserver" in window &&
!reduced.matches
) {
observer = new IntersectionObserver(
function(entries) {
entries.forEach(function(entry) {
if (!entry.isIntersecting) return;
showReveal(entry.target);
observer.unobserve(entry.target);
});
},
{
threshold: 0,
rootMargin: "0px 0px -25px 0px"
}
);
}
scanReveal();
/* 09 - NOUVEAUX BLOCS DYNAMIQUES */
let scanQueued = false;
const mutationObserver =
new MutationObserver(function(records) {
const added = records.some(
function(record) {
return Array.from(
record.addedNodes
).some(function(node) {
return node.nodeType === 1 &&
!node.closest?.("#mc24-exit");
});
}
);
if (!added || scanQueued) return;
scanQueued = true;
requestAnimationFrame(function() {
scanQueued = false;
scanReveal();
});
});
mutationObserver.observe(
document.body,
{
childList: true,
subtree: true
}
);
/* 10 - NETTOYAGE DES OBSERVATEURS */
window.mc34RevealV10Cleanup = function() {
observer?.disconnect();
mutationObserver.disconnect();
document.querySelectorAll(
".mc34-v10-hidden"
).forEach(showReveal);
};
document.documentElement.setAttribute(
"data-mc34-global",
"v12"
);
}
if (document.readyState === "loading") {
document.addEventListener(
"DOMContentLoaded",
init,
{ once: true }
);
} else {
init();
}
})();
/* FIN JAVASCRIPT GLOBAL V12 */