1/* CW â The Dark : Preloader 2 * 3 * Simulates page-load progress, then hands off to the site with a staged exit: 4 * 1. fade the logo / percentage out (so they never ghost over the page), 5 * 2. dissolve the now-blank panel to reveal the content beneath, 6 * 3. fire 'cw:reveal' only once the panel is gone, so the hero entrance 7 * (motion.js) animates on a cleared stage instead of overlapping the loader. 8 */ 9(function () { 10 'use strict'; 11 12 var preloader = document.getElementById('cw-preloader'); 13 var numEl = preloader && preloader.querySelector('.cw-pre__num'); 14 var barEl = preloader && preloader.querySelector('.cw-pre__bar span'); 15 16 if (!preloader || !numEl || !barEl) { 17 return; 18 } 19 20 // Exit choreography (ms). Kept short so the hand-off never feels laboured. 21 var HOLD_AT_FULL = 200; // beat at 100% so completion registers 22 var INNER_CLEAR = 300; // logo/percentage fade (matches CSS ~0.32s) 23 var PANEL_FADE = 700; // panel dissolve failsafe (matches CSS 0.6s + margin) 24 25 var pct = 0; 26 var interval; 27 var isComplete = false; 28 29 function updateProgress(newPct) { 30 pct = Math.min(100, Math.max(0, newPct)); 31 numEl.textContent = Math.round(pct); 32 barEl.style.width = pct + '%'; 33 } 34 35 function complete() { 36 if (isComplete) return; 37 isComplete = true; 38 39 clearInterval(interval); 40 updateProgress(100); 41 42 // Beat at 100%, then run the two-stage exit. 43 setTimeout(function () { 44 // Stage 1: clear the loader's own content. 45 preloader.classList.add('is-clearing'); 46 47 setTimeout(function () { 48 // Stage 2: dissolve the blank panel to reveal the page. 49 preloader.classList.add('done'); 50 51 var revealed = false; 52 function reveal() { 53 if (revealed) return; 54 revealed = true; 55 56 // Hand off to the site once the panel is actually gone. 57 window.__cwRevealed = true; 58 window.dispatchEvent(new CustomEvent('cw:reveal')); 59 60 if (preloader.parentNode) { 61 preloader.parentNode.removeChild(preloader); 62 } 63 } 64 65 // Prefer the real end of the dissolve; fall back on a timer. 66 preloader.addEventListener('transitionend', function (e) { 67 if (e.target === preloader && e.propertyName === 'opacity') { 68 reveal(); 69 } 70 }); 71 setTimeout(reveal, PANEL_FADE); 72 }, INNER_CLEAR); 73 }, HOLD_AT_FULL); 74 } 75 76 // Simulate progress with a non-linear ramp, holding near the end until the 77 // real page load completes. 78 function tick() { 79 if (pct < 90) { 80 updateProgress(pct + (Math.random() * 15 + 10)); 81 } else if (pct < 98) { 82 updateProgress(pct + (Math.random() * 3 + 2)); 83 } 84 // Hold at 98% until actual load completes. 85 } 86 87 interval = setInterval(tick, 40); 88 89 // Complete on the real window load (or immediately if already loaded). 90 if (document.readyState === 'complete') { 91 complete(); 92 } else { 93 window.addEventListener('load', complete); 94 } 95 96 // Failsafe: complete after 1.5s even if the load event never fires. 97 setTimeout(complete, 1500); 98})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.