/* Campfire page: the 3D scene starts only when someone presses the button. The scene itself is campfire.js. */ (function () { 'use strict'; var viz = document.getElementById('fireViz'), host = document.getElementById('fireHost'), poster = document.getElementById('firePoster'); var start = document.getElementById('fireStart'), snd = document.getElementById('fireSnd'), fs = document.getElementById('fireFs'), hint = document.getElementById('fireHint'); var reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; var api = null; function setSnd(on) { snd.setAttribute('aria-pressed', on ? 'true' : 'false'); snd.textContent = on ? 'Sound on' : 'Sound off'; } function sync() { if (!api) return; api.setRunning(!document.hidden); if (document.hidden && api.isOn()) api.toggleSound().then(setSnd); } start.addEventListener('click', function () { start.disabled = true; start.textContent = 'Lighting...'; setTimeout(function () { try { api = window.Campfire.start(host, { reduce: reduceMotion }); } catch (e) { start.disabled = false; start.textContent = '3D is not available here'; return; } host.setAttribute('role', 'img'); host.setAttribute('aria-label', 'A 3D campfire at night, burning in real time'); poster.classList.add('gone'); start.hidden = true; snd.hidden = false; fs.hidden = !viz.requestFullscreen || window.self !== window.top; hint.textContent = 'Drag to look around.'; sync(); }, 40); }); snd.addEventListener('click', function () { if (!api) return; api.toggleSound().then(setSnd, function () { snd.textContent = 'Sound unavailable'; }); }); fs.addEventListener('click', function () { try { (document.fullscreenElement ? document.exitFullscreen() : viz.requestFullscreen()).catch(function () {}); } catch (e) {} }); document.addEventListener('fullscreenchange', function () { fs.textContent = document.fullscreenElement ? 'Exit full screen' : 'Full screen'; }); document.addEventListener('visibilitychange', sync); })();