Spaces:
Running
Running
File size: 2,548 Bytes
03c9ca7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | /* Click-to-load embed facades. HF Space iframes load only after a click (which also records the
"demos" consent for the session) — no third-party frames, no cookies, before that. */
(function () {
window.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('.embed-facade').forEach(function (f) {
f._orig = f.innerHTML; // kept so the facade can collapse back (accordion behaviour)
function collapseOthers() {
document.querySelectorAll('.embed-facade.loaded').forEach(function (o) {
if (o === f) return;
o.classList.remove('loaded'); o.removeAttribute('data-loaded');
o.innerHTML = o._orig || '';
});
}
function load() {
if (f.getAttribute('data-loaded') === '1') return;
var src = f.getAttribute('data-src');
if (!src) { // e.g. simulator while not PRO → go buy Pro Access
if (f.id === 'facade-sim') location.href = 'pricing.html#pro';
return;
}
f.setAttribute('data-loaded', '1');
try {
var c = window.Consent && window.Consent.get();
if (c) window.Consent.set({ analytics: c.analytics, demos: true });
} catch (e) {}
collapseOthers();
var ifr = document.createElement('iframe');
ifr.src = src;
ifr.loading = 'lazy';
ifr.title = f.getAttribute('data-title') || 'demo';
ifr.setAttribute('allow', 'autoplay; fullscreen; microphone; clipboard-write');
ifr.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms allow-downloads allow-popups');
f.innerHTML = '';
f.appendChild(ifr);
f.classList.add('loaded');
f.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
// delegation so restored facades keep working after a collapse
f.addEventListener('click', function (e) {
if (e.target.closest('button') || e.target === f) load();
});
// if the visitor already accepted demo embeds, load the demo as soon as its section scrolls in
if ('IntersectionObserver' in window) {
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (en) {
if (!en.isIntersecting) return;
io.unobserve(f);
try {
var c = window.Consent && window.Consent.get();
if (c && c.demos) load();
} catch (e) {}
});
}, { threshold: 0.25 });
io.observe(f);
}
});
});
})();
|